这个 js reduce 可以很好地处理查询结果:
function toc(current) {
return {....};
};
function getToc(data) {
return = data.reduce((a, c) => Object.assign(a, {[c.id]: toc(c)}), {});
};
const query = db.collection(normCollection)
.where('a_id', '==', a_id )
.where('year', '==', year)
.orderBy("id");
subscriptionNorm = collectionData(query, "id")
.subscribe(data => console.log(getToc(data)));
但是当我使用 RxJs reduce 时,它停止工作。它与流结束有关,但是......但我不明白 RxFire / RxJs 如何处理流式 Firestore 查询结果:
...
subscriptionNorm = collectionData(query, "id")
.pipe(reduce((a, c) => Object.assign(a, {[c.id]: toc(c)}), {}))
.subscribe(data => console.log(data));
更新这个工作正常,但是......:
...
subscriptionNorm = collectionData(query, "id")
.pipe(
map(v => v.reduce((a, c) =>
Object.assign(a, {[c.id]: toc(c)}), {})
),
)
.subscribe(data => console.log(data));