菠菜程序下载 js的for循环中异步请求

在for循环中如果异步请求,菠菜程序下载【企 娥:217 1793 408】则请求回来的数据都是最后一条,则是需要使用js的闭包知识来解决问题。话不多说直接上代码
for(let i=0; i<10; i++) {
(function () {
var str2 = rowDataList[i].poweruserunitids;
var rowData = rowDataList[i];
control.getMonthResultInfoVO(str1, str2, function(resp){
if (resp.isError()) {
if (console && console.log){
console .log("出错啦");
}
}
});
})(i);
}

猜你喜欢

转载自blog.51cto.com/13943431/2165470