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