【发布时间】:2018-07-27 00:26:23
【问题描述】:
有没有更好的方法使用 RxJS 运算符循环从可观察对象返回的数组而不是发出新的单个列表项?
onGetItemData(){
this.dataService.getItemData().subscribe((itemData) =>
{
this.itemDataJSON = itemData;
this.itemDataJSON.forEach(function (value) {
let new_listing = new ListingItem(value.label,value.market,value.name);
console.log(new_listing);
});
});
}
API 返回包含项目的单个数组,因此我无法使用 .map 访问 itemData.name
//-- DataService --//
getItemData(){
return this.http.get(this._URL, { headers })
.pipe(map((res: Listings) => res.items))
}
【问题讨论】:
-
flatten可能是您想要的。this.http.get(this._URL, { headers }) .pipe(flattten(), map(item => item.name))
标签: angular rxjs angular2-observables rxjs-pipeable-operators