【发布时间】:2016-06-09 07:08:31
【问题描述】:
问题描述: 我想从服务器检索产品数组。为此,我有一个执行以下操作的函数:
getProducts(customerId): Observable<Product[]> {
this.http.get(
'http://<url>'+'?productId='+productId)
.map((responseData) => {
return responseData.json();
})
.map((products: Array<any>) => {
let result:Array<Product> = [];
if (products) {
products.forEach((product) => {
result.push(
new Product(product.id,
product.mediaId,
product.description,
product.name));
});
}
return result;
}
我的问题如下: 我想检索需要与产品名称和描述一起显示的每个产品的图像。为了检索图像,我需要调用服务器上的另一个 http 端点并将 product.mediaId 作为参数传递。所以我不清楚的是我该怎么做。我是否需要为上一次 http.get 调用检索到的每个产品再调用一次 http.get 。这样做的 RxJS 可观察和功能性方式是什么?如果有人能对这个问题有所了解,那就太好了。
【问题讨论】:
标签: angular rxjs observable