$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);
异步请求哪个完成就push哪个,会乱是正常的吧;你别用push,直接通过i给下标,注意i值的处理就行了(可以使用IIFE)
有一个思路是构造一个存储结构比如数组array,当异步函数i执行完成后,将数据放回array[i]。
你可以用promise.all方法啊,把请求放进一个数组,这样顺序就不会乱了啊。