$.when
accepts one promise per argument, not an array of promises. If you wish to use an array, you must use .apply
so that you'll apply the array of promises to the .when
method properly.
$.when.apply($,myArrayOfPromises).done(...
Additionally, $.when
returns a promise, so you do not need to generate another one.
var fetchMultipleTracks = function(){
var user_list_count, promises = [];
user_list_count = user_list.length;
for(var i = 0; i < user_list_count; i++ ){
promises.push( getTracks(user_list[ i ]) );
}
return $.when.apply($, promises );
};
To handle the results, iterate over the arguments array.
get_tracks.done(function(){
$.each(arguments,function(i,result) {
console.log(result)
outputTracksToDom(result.toptracks.track);
});
}).fail(function(error ){
// handle error
});