问题描述
下面带有一个 api 请求的代码运行良好。但不是在 forEach 循环中查找,而是想从另一个 API 调用中获取数据,这不起作用,因为它返回函数的值和稍后收到的响应,结果视图没有更新。
getResults: Observable<Entity> {
const entityData= [{id: '3',name:'abc',products: []},{id: '4',name: 'xyz',products: []}];
return this.service.getResults().pipe(
map((data) => this.convert(data,entityData)));
}
convert(item,entityData): any {
let values=[];
const node: {
products: item.products ? item.products : [],expand: true //getting result(true/false) from another function.
}
values.push(node);
node.products.forEach((childUnit)=> {
const result = entityData.find(a=>a.id==childUnit.id));
// want result from another api call,which returns the observable.
// Once all the result get iterated then want to return the {Values}.
// this.service.getresultById(item.id).subscribe((data)=>{this.convert(data)})
const child = this.convert(result,entityData);
values = values.concat(child);
});
return {values};
}
任何帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)