因为在最新版本中从angularfire2中删除$ key我试图在我的getAll服务方法返回之前添加密钥,如:
getAll(): Observable<any> {
return this.loginService.loginData.take(1).flatMap( userdata => {
var RefItems = this.loginService.afDB.list(`/games/${userdata.gameid}/categories/`);
RefItems.snapshotChanges().map(categories => {
return categories.map(m => ({ key: m.key, ...m.payload.val() }));
});
return RefItems.valueChanges().map( categories => {
return categories.map((category) => {
category["matches"] = this.matchesService.getAll(category["key"]);
return category;
})
});
})
}
但似乎是为了迟到(关键不在valueChanges方法中),有人对我有所了解吗? :)
我不知道问题到底在哪里。并不确定是什么部分:
return RefItems.valueChanges().map( categories => {
return categories.map((category) => {
category["matches"] =
this.matchesService.getAll(category["key"]);
return category;
})
});
做,但你可以尝试修改代码形式:
getAll(): Observable<any> {
return this.loginService.loginData.take(1).flatMap( userdata => {
this.loginService.afDB.list(`/games/${userdata.gameid}/categories/`)
.snapshotChanges().map(categories => {
return categories.map(m => ({ key: m.key}));
}).subscribe(vals => {
return vals.map(val=> val.key);
});
});
}
它可能会调用可能无法将订阅分配给Observable,但您会想出来。希望它对你有所帮助