【发布时间】:2019-01-14 12:10:40
【问题描述】:
新手问题:
我正在尝试将我的数据从 rest API 导出到 firebase。
我正在使用 Angular6 和 RxJS 6。
getByTag(tag:string) {
return this.http.get(this.URL + '/get/listings/', { headers })
.pipe(
map((res: Listings) => res.items),
// How do I add an additional property to each of these items? eg res.items.inserted = new Date();
// How do chain each of these res.items to another function called exportToFirebase(res.item))
);
}
我的数据如下所示: https://pasteboard.co/HWp1hUb.jpg
我尝试了 map 函数,但我从 API 传入的数据流是一个数组数组,所以 我尝试了mergeMap但没有成功 (https://www.learnrxjs.io/operators/transformation/mergemap.html)
我尝试使用do() 语句来触发exportToFirebase(res.item),但看起来我完全偏离了轨道:-P
预期结果:创建一个循环以将列表类型的项目参数发送到我的服务函数exportToFirebase(res.item)
有问题吗?
如何为这些项目中的每一项添加附加属性?例如
res.items.inserted = new Date();?如何将这些
res.items链接到另一个名为exportToFirebase(res.item))的函数?
【问题讨论】:
-
那么你的问题是
exportToFirebase(res.item)返回一个Observable?