I know this has been asked before but I can't figure out my scenario from the typical answers provided.
(我知道以前已经有人问过这个问题,但是我无法从提供的典型答案中弄清楚我的情况。)
In my app I have firebase collection called objectives and a tasks collection that have a one to many relationship. (在我的应用程序中,我有称为目标的firebase集合和具有一对多关系的任务集合。)
Each objective has a tasks array (filled with the ID's of the tasks) and each task has an objectiveId. (每个目标都有一个任务数组(填充有任务的ID),每个任务都有一个ObjectiveId。)
I would like to join these so when I make a snapshotChanges() call to get all objectives I would like to return an array of objectives with tasks objects nested in. (我想加入这些对象,所以当我进行snapshotChanges()调用以获取所有目标时,我想返回一个嵌套了任务对象的目标数组。)
I have this code and I know it does not work cuz I can't return something in an observable but I was wondering how would I use RxJS operators in this case?
(我有这段代码,我知道它不起作用,因为我无法以可观察的方式返回某些内容,但是我想知道在这种情况下如何使用RxJS运算符?)
loadObjectives() {
return this.objectivesCollection.snapshotChanges().pipe(
map(actions => {
return actions.map(_ => {
const id = _.payload.doc.id;
const data = _.payload.doc.data();
const tasks = this.afs
.collection<Task>("tasks", ref =>
ref.where("objectiveId", "==", id)
)
.valueChanges().subscribe( tasks => {
return new Objective(id, data.title, tasks);
});
});
}),
tap(objectives => {
this._objectives.next(objectives);
})
);}
ask by Faisal Choura translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…