如何基于数组从另一个对象返回的结果执行另一个可观察对象

How to execute another observable based on array from result returned from another one

我的情况很简单,但我卡住了。我有函数 customGalleriesHttpService.list(),其中 return 可以通过项目数组观察到。让我们假设:

[
{id:1,
... other stuff
},
{id:2,
... other stuff
}
]

现在我想从这个数组中取出每个元素并发出一个额外的 http 请求 customGalleriesHttpService.images(data.id),return 可以根据他的 id 为特定元素的图像数组观察到该请求。到目前为止我取得了什么。

    this.customGalleriesHttpService.list().pipe(
      concatMap((data) => data),
      mergeMap((data) => this.customGalleriesHttpService.images(data.id)),
    ).subscribe((data) => console.log(data));

它正在运行,但还有更多内容。它给我这样的输出:

数组[6], 数组[6]

我想要实现的是将它和 return 分组 [数组[6], 数组[6]]

在订阅之前添加一个 toArray() 运算符应该可以工作

this.customGalleriesHttpService.list().pipe(
  concatMap((data) => data),
  mergeMap((data) => this.customGalleriesHttpService.images(data.id)),
  toArray(), 
).subscribe((data) => console.log(data));