multiple jQuery whens' dones? -


i can pass in multiple ajax calls when this:

var dnlday = []; (i=0, imax=urlstoload.length; < imax; i++) {     dnlday.push( $.ajax({         url: urlstoload[i],         datatype: "json"     }) ); }  $.when.apply($, dnlday).done( function( donecb ) {     console.log( donecb ); } 

when when runs getting first donecb array of ajax requests. understand add more parameters done function other callbacks, not extensible. (i going have unknown number of ajax calls in when, cannot know how many parameters need in done function ahead of time).

what right way handle design problem?

the first example in the documentation jquery.when() shows how access arguments individual promises.

however doesn't address how approach unknown number of promises, little knowledge necessary - namely function's arguments made available in array-like object arguments, can looped through follows.

$.when.apply($, dnlday).done( function() {     for(i=0; i<arguments.length; i++) {         var donecb = arguments[i];         console.log( donecb );     } } 

each donecb array containing value(s) corresponding promise resolved.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -