【发布时间】:2015-09-09 22:27:43
【问题描述】:
我需要检查所有 $http 请求处理的“for 循环”函数何时完成,并且可以一劳永逸地刷新数据网格。目前,每个 $http 请求都会进行刷新,这是不希望的行为。
已经阅读了一些关于 angularjs $q.all 的内容,但不确定在以下场景中的实现。
非常感谢任何帮助/建议。提前致谢。
这里是sn-p -
function chainedAjax(param1, param2) {
var something = something;
$http({
// processing
}).then(function(responseData) {
// processing
return $http({
// processing
});
}, function(ex) {
// error
}).then(function(responseData) {
// processing
return $http({
// processing
});
}, function(ex) {
// error
}).then(function(responseData) {
// success - Done
finish();
}, function(ex) {
// error
});
}
function init(selectedDocs) {
var something = something;
angular.forEach(selectedDocs, function(item, arrayIndex) {
chainedAjax(item.param1, item.param2);
});
}
function finish() {
refreshDocsTable(); // refreshes the current grid
}
init(selectedItems); // call init function
【问题讨论】:
-
请不要将sn-ps用于不需要运行的代码。
-
完成。感谢您的建议:-)
-
我已经为你修好了...