【发布时间】:2019-01-20 23:39:04
【问题描述】:
Observable.forkJoin(this.cdsDataService.getServersForComponent().map(one => this.Servers = one),
this.cdsDataService.getComponentForServer().map(two => this.Components = two))
.subscribe(res => {
//for these ids more http calls are made
for (let comp of this.Components) {
this.compIds.push(comp.ID);
//does not wait for this http call to complete
this.getObjectsById();
SomeMethod();
}}
);
getObjectsById()
{
let observableBatch = [];
this.compIds.forEach((key) => {
observableBatch.push(this.cdsDataService.getComponentLinks(key).subscribe(p => {
//console.log(key);
for (let it of p) {
let nodelink = {from: key, to: it.ID, color: "blue"};
this.componentLinkData.push(nodelink);
}
// console.log(p);
}));
});
return Observable.forkJoin(observableBatch);
}
getComponentForServer() 返回 getObjectsById() 使用的 id
getObjectsById() 循环遍历 id 并对每个 id 进行 http 调用。
我无法让程序等待来自getObjectsById() 的所有调用完成。
它只是跳转到SomeMethod();
我们将不胜感激。
【问题讨论】: