我有以下内容:
zip(this.baskets$.asObservable(), this.products$.asObservable()).
pipe(
map(([baskets, products]) => /* get basket and product */),
map(([basket, product]) => /* use basket and product in condition */)
);
在给定的Map
和basket
的情况下,如何首先product
获得basketId
和productId
?
我知道如何获得它们……类似
let basket = baskets.find(x => x.id == data.basketId);
let product = products.find(x => x.id == data.productId);
但是如何在第二个map
中通过和使用两者:
map(([basket, product]) => /* use basket and product in condition */)
答案 0 :(得分:2)
您快到了:
zip(this.baskets$,this.products$).pipe(
map(([baskets,products]) => {
const basket = baskets.find(bskt => bskt.id === this.data.basketId);
const product = products.find(prdct => prdct.id === this.data.productId);
return [basket,product];
}),
map(([basket,product]) => /*now use them here*/)
)
当然,如果找不到ID,则可能在第二张地图中未定义它们。