本文介绍了forkjoin没有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用forkJoin合并两个Firebase请求的结果
I'm using forkJoin to combine the results of two firebase requests
这两个请求都已完成并在控制台中登录,但是forkJoin本身的map函数不会触发,因此没有结果返回给应用程序
Both requests complete and log within the console, but the map function for the forkJoin itself does not fire and hence no results are returned to the application
public initGroup(groupname, username){
console.log(groupname, username)//This logs
return Observable.forkJoin([
this.getGroup(groupname, username),
this.groupMembers(username, groupname),
])
.map((data)=>{
console.log(data)//This does not log
this.group = data;
return this.group
})
}
对于单个功能:
public getGroup(groupname, username){
return (this._af.database.object('/groups/'+groupname) as FirebaseObjectObservable<any>)
.map((group)=>{
console.log(group)//This logs
return group
})
}
public groupMembers(username, groupname){
return this.afService.getUserItems(groupname)
.map((users:UserInfo[])=>{
console.log(users)//This logs
return users
})
}
我在组件内订阅
let conn = this.groupService.initGroup(groupname, username)
.subscribe((data)=>{
console.log(data)//Does not log
......
})
推荐答案
事实证明forkJoin不适用于Firebase可观察对象,
It turns out forkJoin just doesn't work with firebase observables,
当我更新到
public initGroup(groupname, username){
return Observable.combineLatest([
this.getGroup(groupname, username),
this.groupMembers(username, groupname)
])
.map((data)=>{
console.log(data)//This now logs
this.group = data;
return this.group
})
}
combineLatest使它按预期工作
combineLatest made it work as expected
这篇关于forkjoin没有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!