【发布时间】:2018-09-04 13:08:08
【问题描述】:
我正在尝试使用 switchMap 运算符切换可观察对象:
return this.db.list(`UserPlaces/${this.authData.auth.auth.currentUser.uid}`, {
query: {
orderByChild: 'deleted',
equalTo: false
}
})
.map((locations:any)=>{
console.log(JSON.stringify(locations,null,2));
return locations.map(location=>{
return location.$key;
});
}).flatMap(locations=>{
return locations
}).switchMap(location=>{
console.log(location);
return this.db.object(`Devices/${location}`)
})
.do(console.log);
我得到一个 observable 而不是 observable 数组。
我需要获取“this.db.object(
Devices/${location})”的数组
如何解决?
谢谢。
【问题讨论】:
-
您正在使用
flatMap(locations => locations)展平阵列。然后为每次发射调用switchMap。 -
感谢您的回复,,,,我颠倒了 switchMap 和 flatMap 的位置,它现在可以工作了,但我仍然有如何合并 flatMap 运算符发出的分离对象,实际上任何相反的flatMap的,你有什么想法
标签: javascript angular typescript firebase rxjs