【发布时间】:2020-03-08 14:51:49
【问题描述】:
我正在尝试使用 AngularFire 合并来自 Firebase 的 2 个数据流,但我遇到了困难。
我有一个名为 incomeShops 的集合,其中包含创建该特定记录的 userID 的引用。我需要做的是再次调用以获取用户的数据,但我不能。
有什么帮助吗?
这是我所拥有的:
getAllIncomeShops() {
const shops = this.venueService.getIncomeShops()
.snapshotChanges()
.pipe(
switchMap(incomeShopSnaps => {
// Mapping the result to extract the data I need using snapshotchanges().
return incomeShopSnaps.map(incomeShopSnap => {
const shopObject = {
id: incomeShopSnap.payload.doc.id,
...incomeShopSnap.payload.doc.data()
};
// On the shopObject there is a property called suggestedBy which contains a STRING with the user's ID.
// Trying to fetch the user's data to insert on the shopObject.
this.userService.getUser(shopObject.suggestedBy).valueChanges()
});
})
).subscribe(data => {
console.log(data);
});
}
【问题讨论】:
-
那么对于每个
incomeShopSnaps,您想提出一个单独的请求吗? -
嘿@martin 是的!
标签: firebase rxjs angularfire2