我有一個非常簡單的情況,但我被卡住了。我有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));
它正在作業,但還有更多事情要做。它給了我這樣的輸出:
陣列[6],陣列[6]
我想要實作的是對它進行分組并回傳 [Array[6], Array[6]]
uj5u.com熱心網友回復:
toArray()在訂閱之前添加一個運算子應該可以作業
this.customGalleriesHttpService.list().pipe(
concatMap((data) => data),
mergeMap((data) => this.customGalleriesHttpService.images(data.id)),
toArray(),
).subscribe((data) => console.log(data));
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409239.html
標籤:
上一篇:如何從基于id的服務中獲取資料?
