[英]Use data from one observable in another and then return result as other observable
[英]How to execute another observable based on array from result returned from another one
我有一個非常簡單的情況,但我被卡住了。 我有 function customGalleriesHttpService.list()
它返回帶有項目數組的可觀察對象。 讓我們假設:
[
{id:1,
... other stuff
},
{id:2,
... other stuff
}
]
現在我想從這個數組中取出每個元素並制作一個額外的 http 請求customGalleriesHttpService.images(data.id)
,它根據他的 id 返回帶有特定元素的圖像數組的 observable。 到目前為止我所取得的成就。
this.customGalleriesHttpService.list().pipe(
concatMap((data) => data),
mergeMap((data) => this.customGalleriesHttpService.images(data.id)),
).subscribe((data) => console.log(data));
它正在工作,但還有更多事情要做。 它給了我這樣的 output :
數組[6],數組[6]
我想要實現的是對它進行分組並返回 [Array[6], Array[6]]
在訂閱之前添加一個toArray()
運算符應該可以工作
this.customGalleriesHttpService.list().pipe(
concatMap((data) => data),
mergeMap((data) => this.customGalleriesHttpService.images(data.id)),
toArray(),
).subscribe((data) => console.log(data));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.