【发布时间】:2021-10-09 19:06:33
【问题描述】:
您好,我有一个 API 调用 getItems(),它返回如下数据:
[
{
name: 'item1',
materials: [
1,
2,
3,
],
},
{
name: 'item2',
materials: [
2,
3,
6,
],
}
...
]
另一个 API 调用 getMaterial(id) 会返回这样的材料数据:
{
name: 'mat1',
img: '/img.jpg'
}
我试图实现的是使用材料数据获取所有项目数据。我设法获得了所有可观察到的材料要求,但我不知道之后该做什么。
这就是我到目前为止所做的:
public getAllItemsData(): Observable<any> {
return getItems().pipe(
map((list: items[]) => {
return list.map(item => {
const allMat = item.materials.map(m => getMaterial(m))
return forkJoin(allMat).pipe(
map(data => {
return {
...item,
materials: data
}
})
)
})
}),
);
}
但它不起作用。感谢您的帮助。
【问题讨论】:
标签: angular typescript rxjs