嵌套的RXJS映射操作员的目的是什么?
我目前正在进行在线角度课程,我意识到RXJS在Web开发中广泛使用。我正在尝试,遇到了一个嵌套的地图操作员,我可以理解正在发生的事情,但我似乎无法在上面找到很多信息。
this.productService.getProducts().pipe(
map(products =>
products.map(product => {
const data = {...product.payload.val() as Product};
return data;
}))).subscribe(p => this.products = p)
因此,从我的理解中,GetProducts()函数返回可观察到的列表,然后外部地图运算符会发出可观察到的单个可观察到的内部地图运算符,然后我可以从HTTP响应中访问有效载荷数据?如果这是正确的,是否有一种更轻松/更清洁的方法来执行此功能?
I am currently doing an online Angular course and I realized that RxJS is quite broadly used in web development. I was experimenting and I came across a nested map operator and I can kind of make sense of what is happening but I cant seem to find much information on it.
this.productService.getProducts().pipe(
map(products =>
products.map(product => {
const data = {...product.payload.val() as Product};
return data;
}))).subscribe(p => this.products = p)
So from my understanding is that the getProducts() function returns a list of Observables, then the outer map operator would emit an individual Observable into the inner map operator which then allows me to access the payload data from the http response? If this is correct, isnt there an easier/cleaner way of performing this functionality ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您开始时,RXJS是一次很棒的冒险。
我从代码中的猜测是GetProducts()返回可观察到的可观察到的产品,该可观察到存储在产品中的产品
。
也可以通过:
https:// https://stackblitz.com/editit/dyit/typescript/typescript/typescript/typescript -3jed7f?file = index.ts
RxJS is quite a wonderful adventure when you start with it.
my guess from the code is the getProducts() returns an Observable that emits an Array of Products that are stored in product.payload.val
The map function then transforms the payload from GetProducts() to a typed array of Products.
It could also be done via:
https://stackblitz.com/edit/typescript-3jed7f?file=index.ts