Angularjs 在forEach完成后调用函数
我有一个方法,只有在forEach块完成执行后才需要调用它。现在在我的代码中,函数在我的forEach块执行之后首先被调用。这是一段代码Angularjs 在forEach完成后调用函数,angularjs,Angularjs,我有一个方法,只有在forEach块完成执行后才需要调用它。现在在我的代码中,函数在我的forEach块执行之后首先被调用。这是一段代码 function processData(data) { angular.forEach(data.ITINERARY.LIST_BOUNDS, function(bound, boundIndex) { angular.forEach(bound.LIST_SEGMENT, function(segment, index)
function processData(data) {
angular.forEach(data.ITINERARY.LIST_BOUNDS, function(bound, boundIndex) {
angular.forEach(bound.LIST_SEGMENT, function(segment, index) {
$q.all([
ServiceLocationAssistant.getAirport(segment.ORIGIN.LOCATION_CODE),
ServiceLocationAssistant.getAirport(segment.DESTINATION.LOCATION_CODE)
])
.then(function(locations) {
segment.ORIGIN.location = locations[0];
segment.DESTINATION.location = locations[1];
});
});
});
$scope.flightSection(processedData);//This method needs to be called
}
不,foreach肯定会在它之后的
flightSection
调用之前执行。承诺很可能会晚些完成,不是吗?!我们需要更多地了解异步代码需要做些什么,才能在这里提出一个好的解决方案。我必须在每个块中使用一些值来设置JSON,然后我必须在Flight部分中对更改后的JSON执行一些操作。