我有一个集合的市场,每个市场都有一个产品的集合。我正试着查询以得到所有的..。最后,我得到了一个解决方案,但是我在第9行得到了关于compineLatest的提示:"@deprecated参数在一个数组中“。
我想知道是否有更好的and,以及如何正确地使用compineLatest。
//#region fetch method
private fetch(marketsRef: AngularFirestoreCollection<Market>) {
return marketsRef
.snapshotChanges()
.pipe(
switchMap(markets => {
if (!markets.length) {
this._noDataSubject$.next(true);
}
return combineLatest([markets],
combineLatest(
markets.map(market => {
return this.firestore.collection<MarketProduct>(`markets/${market.payload.doc.id}/products`, ref => {
return ref.orderBy('reviewResult')
})
.snapshotChanges()
})
)
)
}), map(([markets, products]) => {
const allProducts = products.reduce((acc, val) => acc.concat(val), []);
const returnedMarkets = markets.map(market => {
return {
id: market.payload.doc.id,
...market.payload.doc.data() as Market,
products: allProducts
.filter(product => product.payload.doc.ref.path === `markets/${market.payload.doc.id}/products/${product.payload.doc.id}`)
.map(product => {
return {
id: product.payload.doc.id,
...product.payload.doc.data() as MarketProduct
}
})
}
}) as MarketId[];
return returnedMarkets;
}))
}
//#endregion fetch method
//#region fetch new markets request
fetchNewMarkets() {
const key = `name.ar`;
const marketsRef = this.firestore.collection<Market>('markets', ref => {
return ref.where('reviewResult', '==', null).orderBy(key);
});
this.fetch(marketsRef)
.subscribe(markets => {
this._marketsChanges$.next(markets);
})
}
//#endregion fetch new markets request发布于 2020-11-26 08:01:03
return combineLatest([markets], combineLatest(/* ... */));你有这条线。第一个combineLatest有两个参数。不推荐使用签名combineLatest(...obs)。您所需要做的就是将第二个combineLatest添加到数组中。
return combineLatest([markets, combineLatest(/* ... */)]);编辑,附加建议
// const allProducts = products.reduce((acc, val) => acc.concat(val), []);
const allProducts = products.flat();发布于 2020-11-28 19:41:49
我的终端代码
//#region fetch method
private fetch(marketsRef: AngularFirestoreCollection<Market>) {
return combineLatest([
marketsRef.snapshotChanges(),
marketsRef.snapshotChanges()
.pipe(
switchMap(markets => {
if (!markets.length) {
this._noDataSubject$.next(true);
}
return combineLatest(
markets.map(market => {
return this.firestore.collection<MarketProduct>(`markets/${market.payload.doc.id}/products`, ref => {
return ref.orderBy('reviewResult')
})
.snapshotChanges()
})
)
})
)]).pipe(map(([markets, products]) => {
const allProducts = products.reduce((acc, val) => acc.concat(val), []);
return markets.map(market => {
return {
id: market.payload.doc.id,
...market.payload.doc.data() as Market,
products: allProducts
.filter(product => product.payload.doc.ref.path === `markets/${market.payload.doc.id}/products/${product.payload.doc.id}`)
.map(product => {
return {
id: product.payload.doc.id,
...product.payload.doc.data() as MarketProduct
}
})
}
}) as MarketId[];
}));
}
//#endregion fetch method
//#region fetch new markets request
fetchNewMarkets() {
const key = `name.ar`;
const marketsRef = this.firestore.collection<Market>('markets', ref => {
return ref.where('reviewResult', '==', null).orderBy(key);
});
this.fetch(marketsRef)
.subscribe(markets => {
this._newMarketsChanges$.next(markets);
})
}
//#endregion fetch new markets requesthttps://stackoverflow.com/questions/65014988
复制相似问题