【发布时间】:2017-11-17 23:36:56
【问题描述】:
我无法执行承诺循环。
我拨打服务电话以获取提供商列表,然后对于每个提供商,我再拨打服务电话以获取客户。
供应商有 1 个或多个客户。所以最终的客户名单是要装饰和展示的。
我正在尝试实现的其他格式:
*serviceA.getProvider(){
foreach(providers){
foreach(provider.customerID){
serviceB.getCustomer(customerId)
}
}
}
.then(
foreach(Customer){
updateTheCustomer;
addUpdatedCustomerToAList
}
displayUpdatedCustomreList();
)*
我写了下面的代码,但不起作用
doTheJob(model: Object) {
let A = [];
let B = [];
let fetchP = function(obj) {
obj.Service1.fetchAllP().then(function (response) {
let P = cloneDeep(response.data);
_.forEach(P, function(prov) {
_.forEach(prov.CIds, function(Id) {
A.push(Id);
});
});
_.forEach(A, function(CId) {
return obj.Service2.getById(CId);//what works is if this statement was: return obj.Service2.getById(A[0]);
//So, clearly, returning promise inside loop isn't working
});
})
.then(function(response) {
B.push(response.data); //This response is undefined
angular.forEach(B, function (value) {
obj.updateAdr(value)
});
obj.dispay(B);
});
};
fetchP(this);
}
【问题讨论】:
标签: angularjs loops user-interface promise q