如何在所有異步調用完成時停止函數? 我有誰遞增VAR槽一個異步調用或沒有(與if條件)的列表上的foreachAngularJs異步問題
我的代碼:
$scope.updateDureePeriodeList = function() {
var mttLoyer = 0
angular.forEach($scope.articleListDuree, function (value, key) {
if (value.selected) {
if (value.bOption) {
$scope.getTauxDevisRevOption(value.prixArt * value.qttArt).then(function (taux) {
mttLoyer += value.prixArt * value.qttArt * taux/100;
})
}
else
mttLoyer += value.prixArt * value.qttArt * $scope.DureeEdit.taux/100;
}
});
$scope.DureeEdit.periodeList = new Array();
$scope.DureeEdit.periodeList.push({
'numPeriode': 1,
'mttLoyer': parseFloat(mttLoyer).toFixed(2),
});
}
問題:getTauxDevisRevOption是異步,當我進去吧,我功能不停止,因此做$scope.DureeEdit.periodeList.push
在年底前mttLoyer是異步調用中。然後)增量(...
搜索如何處理javascript中的異步操作 – Hitmands
我已經完成了我的搜索並找到了答案,以處理帶有承諾的異步(即我調用getTauxDevisRevOption時執行的操作),但是在這種情況下,沒有找到答案,因爲我不能做的.then()所有的代碼,因爲我需要完成我的循環之前打電話給我在函數結束:/ – rob1