为了账号安全,请及时绑定邮箱和手机立即绑定

for循环执行多个异步请求,但是请求到的数据顺序打乱了?

for循环执行多个异步请求,但是请求到的数据顺序打乱了?

隔江千里 2018-11-28 22:18:34
$http({        'url':'/jtkj/yjmc',        'method':'POST',    })    .success(function(res) {        $scope.yjdh = res;        console.log(res);        var navUrl = ['/genSit','/news','/set','/manage','/cooperate','/admNet','/eplNet','/stuMan'];        //传值,循环遍历出数据        $scope.xlcd = [];        for(var i=0;i<res.length;i++){            $scope.yjid = res[i].yjid;            console.log(res[i].yjid);            ejnameGet($scope.yjid);            $http({                url:'/jtkj/ejmc',                method:'POST',                data:{yjid:$scope.yjid}            }).success(function(xlcd1){                //$scope.xlcd = xlcd1;                console.log(xlcd1);                xlcd.push(xlcd1);            })        }        //console.log($scope.xlcd);        $scope.xlcd = xlcd;        console.log($scope.xlcd);
查看完整描述

1 回答

?
吃鸡游戏

TA贡献1829条经验 获得超7个赞

异步请求哪个完成就push哪个,会乱是正常的吧;你别用push,直接通过i给下标,注意i值的处理就行了(可以使用IIFE)


查看完整回答
反对 回复 2018-12-19
  • 1 回答
  • 0 关注
  • 440 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号