Angularjs 如何在我的2个forEach上使用$q?
我每人有两个角 第二个直到第一个完成后才能开始:Angularjs 如何在我的2个forEach上使用$q?,angularjs,angular-promise,chain,Angularjs,Angular Promise,Chain,我每人有两个角 第二个直到第一个完成后才能开始: $scope.rendezVous.j_plaignant = []; angular.forEach(data.data,function(objet){ if(objet.idpartie==1){ $scope.rendezVous.j_plaignant.push(objet.idjuriste); } }) $scope.rendezVous.juristes_plaignant = []; ang
$scope.rendezVous.j_plaignant = [];
angular.forEach(data.data,function(objet){
if(objet.idpartie==1){
$scope.rendezVous.j_plaignant.push(objet.idjuriste);
}
})
$scope.rendezVous.juristes_plaignant = [];
angular.forEach(data.data,function(objet){
if(objet.idpartie==1){
$scope.rendezVous.juristes_plaignant.push(objet);
}
})
我试过这个,但运气不好:
var defer = $q.defer();
$scope.rendezVous.j_plaignant = [];
angular.forEach(data.data,function(objet){
if(objet.idpartie==1){
$scope.rendezVous.j_plaignant.push(objet.idjuriste);
}
})
$q.all($scope.rendezVous.j_plaignant).then(lastTask);
function lastTask(){
$scope.rendezVous.juristes_plaignant = [];
angular.forEach(data.data,function(objet){
if(objet.idpartie==1){
console.log(objet);
$scope.rendezVous.juristes_plaignant.push(objet);
}
})
}
如果你有一个想法就好了,$q很难理解
我不明白为什么我不能添加一个。然后在一个forEach之后,它太烦人了,我无法理解$q。我认为你不需要延迟
当第二个
forEach
发生时,第一个就完成了。这是同步的。由于显示的代码段都是同步的,因此代码中缺少了一些内容。两个forEach
块是否在不同的块中。然后是块?请澄清您的问题。甚至不清楚为什么您需要每人两个……或者您有什么具体问题为什么需要使用$q
?你的第一个应该已经做了你想做的,在第一个完成之前不要启动第二个forEach
。