在 ajax 请求中,我需要使用从 ajax 请求返回的页面更新 olist[i] 。如何使 i 等于正确的索引,以便正确设置页面?我尝试将 _index: i 添加到 ajax,但无法访问它。
function GetPagesList() {
var str, page;
var deferredArr = [], deferr;
startTime = +new Date;
for (var i = 0; i < olist.length; i++) {
str = [];
if (olist[i].pagelist == 1) {
//
} else {
deferr =
$.ajax({
type: 'POST',
url: 'wfrmHelper.aspx/GetTop10PagesByKey',
data: "{Key: '" + olist[i].Key + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
var o = $.parseJSON(data.d);
if (o != null) {
o.each(function(e, x) {
page = e.WebFormName;
if ($.inArray(page, Pages2Remove) == -1) {
str.push(page);
totalpages++;
}
});
olist[i].Pages = str; // need to set i
}
},
error: function(xhr, ret, e) {
alert('Error');
}
});
deferredArr.push(deferr);
}
}
$.when.apply(this, deferredArr).then(function() {
endTime = +new Date, delta = endTime - startTime;
log('Total Pages ' + " took:" + delta.toString() + "ms");
});
}