如何處理jQueryDeferreds數(shù)組?我有一個需要按一定順序加載數(shù)據(jù)的應用程序:根URL,然后是模式,然后使用模式和各種數(shù)據(jù)對象的URL初始化應用程序。當用戶導航應用程序時,將加載數(shù)據(jù)對象,并根據(jù)架構(gòu)驗證數(shù)據(jù)對象并顯示數(shù)據(jù)對象。當用戶對數(shù)據(jù)進行遍歷時,模式提供了第一次驗證。初始化有問題。我使用Ajax調(diào)用獲取根對象$.When(),然后創(chuàng)建一個承諾數(shù)組,每個模式對象一個。這很管用。我看到控制臺里的東西了。然后,我看到了對所有模式的提取,因此每個$.ajax()調(diào)用都能工作。get chschema()確實會返回一系列承諾。但是,F(xiàn)inalWHERE()子句從未觸發(fā),而“已完成”一詞從未出現(xiàn)在控制臺上。jQuery-1.5的源代碼似乎意味著“NULL”是可以接受的對象,可以傳遞到$.Wh.Apply(),因為如果沒有傳入對象,那么當()構(gòu)建一個內(nèi)部的Deferred()對象來管理列表時,它是可以接受的。這使用了Futures.js。如果不是這樣,應該如何管理jQueryDeferreds數(shù)組? var fetch_schemas, fetch_root;
fetch_schemas = function(schema_urls) {
var fetch_one = function(url) {
return $.ajax({
url: url,
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json"
});
};
return $.map(schema_urls, fetch_one);
};
fetch_root = function() {
return $.ajax({
url: BASE_URL,
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json"
});
};
$.when(fetch_root()).then(function(data) {
var promises = fetch_schemas(data.schema_urls);
$.when.apply(null, promises).then(function(schemas) {
console.log("DONE", this, schemas);
});
});
3 回答

慕森卡
TA貢獻1806條經(jīng)驗 獲得超8個贊
$.when.apply($, promises).then(function(schemas) { console.log("DONE", this, schemas);}, function(e) { console.log("My ajax failed");});
$.when.apply($, promises).done(function() { ... }).fail(function() { ... });`
$
null
this
$.when
jQuery
null
.
$.when
添加回答
舉報
0/150
提交
取消