jQuery将结果作为单独的参数传递。您可以使用它们这样,如果你有一个已知数量的参数,或者如果你没有特别需要它们的排列:
$.when.apply($, promises).done(function(r1, r2, r3, r4, r5) {
// process various results here
});
如果你想获得的参数在一个数组,你有几个选项。
$.when.apply($, promises).done(function() {
var args = Array.prototype.slice.call(arguments);
// now all the arguments are in the args array
});
或者,在适当的ES6环境中,可以使用扩操作:
$.when.apply($, promises).done(function(...args) {
// now all the arguments are in the args array
});
或者,在ES6承诺环境或合适的无极填充工具,你可以用Promise.all()
这确实类似的东西到$.when()
,但接受一个数组作为其初始参数和结果付诸数组:
Promise.all(promises).done(function(arrayOfResults) {
// process various results here
});
所述然后回调将有一个以上的精氨酸(...)(函数(thisAcutallyIsAnArrayOfvalues){' –
}谢谢@Jaromanda X.因为你是第一个答复,正确回答了问题,请将其重新发布为答案,以便我可以接受。 谢谢。 – umair