我正在尝试从Firebase获取信息并使用Rxjs 6对其进行过滤。
对此我有几个问题:
数据库结构:
profile{
NAg0E9IXrjeKMw3tLxPrlyvcdBr2{
name:david,
age:20,
favorite{
NHXL2LD5LIfgdfvr{
name:mike,
uid:gh4Q0OEfNHXL2LD5LIgFpVmdmm92
}
Q0OEfNHX2LD5Ldsdv{
name:ron,
uid:Vmdmm92dNHXL2LD5LIgFpEfNHXL2
}
}
}
gh4Q0OEfNHXL2LD5LIgFpVmdmm92{
name:mike,
age:26,
favorite{
rlyvcdBr25LdsIXrdv{
name:david,
uid:NAg0E9IXrjeKMw3tLxPrlyvcdBr2
}
}
}
}
服务代码:
getDataObj(objpath:string){
this.objRef = this.db.object(objpath);
this.obj = this.objRef.valueChanges();
return this.obj;
}
getDataList(listpath:string){
this.itemsRef = this.db.list(listpath);
this.items = this.itemsRef.snapshotChanges().pipe(
map(changes =>
changes.map(c => ({ key: c.payload.key, ...c.payload.val() }))
)
);
return this.items;
组件代码:
//Here I get Problem 3
this.db.getDataObj("/Profile/" + this.uid).pipe(
map(data => data.favorite.filter((res) => res.uid===this.uid))).subscribe(res=>console.log(res));
//Here I get Problem 2
this.db.getDataList("/Profile/" + this.userAuth.uid + "/favorite").pipe(filter(data => data.uid == this.uid)).subscribe(res => {
console.log(res)});
如果我确实进行过滤,那么它对我有用:
this.db.getDataList("/Profile/" + this.userAuth.uid + "/favorite").subscribe(res => {
console.log(res.filter(names =>names.uid == this.uid));
console.log(res)});
谢谢