我发出了一个http请求,该请求返回具有产品数组的可观察数据.对于这个产品中的每一个,我需要进行http调用,以便获得详细信息. 如何使用RxJ使其并行.现在我有了一个Products.forEach,并最终使其正常工作,但这使用了外部(对于我的方法)BehaviorSubject. 我更喜欢返回一种包含所有细节的串联对象.
return this.apiService.getCart().pipe(
map(({ id, products, quantity }) => {
products.forEach(({ productId }) => this.getProduct(productId).subscribe((product) => this.cart.products.push(product)));
return { id, quantity }
})
)}