如何處理jQueryDeferreds數組?我有一個需要按一定順序加載數據的應用程序:根URL,然后是模式,然后使用模式和各種數據對象的URL初始化應用程序。當用戶導航應用程序時,將加載數據對象,并根據架構驗證數據對象并顯示數據對象。當用戶對數據進行遍歷時,模式提供了第一次驗證。初始化有問題。我使用Ajax調用獲取根對象$.When(),然后創建一個承諾數組,每個模式對象一個。這很管用。我看到控制臺里的東西了。然后,我看到了對所有模式的提取,因此每個$.ajax()調用都能工作。get chschema()確實會返回一系列承諾。但是,FinalWHERE()子句從未觸發,而“已完成”一詞從未出現在控制臺上。jQuery-1.5的源代碼似乎意味著“NULL”是可以接受的對象,可以傳遞到$.Wh.Apply(),因為如果沒有傳入對象,那么當()構建一個內部的Deferred()對象來管理列表時,它是可以接受的。這使用了Futures.js。如果不是這樣,應該如何管理jQueryDeferreds數組? 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貢獻1827條經驗 獲得超9個贊
$.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
- 3 回答
- 0 關注
- 447 瀏覽
添加回答
舉報
0/150
提交
取消