如果从$.each
循环调用jQuery deferrers,我似乎无法工作。
var deferreds = [],
ids = ['1234', '4321'],
users = [];
$.each(ids, function(i,v){
deferreds.push(
$.getJSON('api/users/'+v, function(i,v){
users.push(v.username);
})
);
});
$.when($, deferreds).done(function(){
console.log(users);
});