我正在使用NativeScript和Firebase插件,以便可以通过唯一ID检索输入的数据。我的问题是我只取回ID,而不取回ID内的数据。这是Firebase中的数据结构:https://i.imgur.com/Jehig5r.png
带下划线的是每个日志的ID。
这是点击该项目并将其转到编辑页面的代码:
viewDetail(id: string){
this.router.navigate(["./calendar-detail", id],
{
relativeTo: this.activatedRoute
});
}
编辑组件:
private sub: any;
public log: Observable<any>;
ngOnInit(){
this.sub = this.route.params.subscribe((params: any) => {
this.id = params['id'];
this.firebaseService.getMyLog(this.id).subscribe((log) => {
this.ngZone.run(() => {
for (let prop in log) {
//props
if (prop === "id") {
this.id = log[prop];
}
if (prop === "mood") {
this.mood = log[prop];
}
if (prop === "activity") {
this.activity = log[prop];
}
if (prop === "other") {
this.other = log[prop];
}
}
});
});
});
这是Firebase服务,应该从ID中获取日志数据:
getMyLog(id: string): Observable<any> {
return new Observable((observer: any) => {
observer.next(this._allItems.filter(s => s.id === id)[0]);
}).share();
}
在此代码的html编辑页面上,它显示ID,但不显示“心情”:
<Label class="h2" [text]="mood"></Label>
<Label class="h2" [text]="id"></Label>
我仍然习惯于Nativescript和Angular,因此我不太确定自己是否犯了一个愚蠢的错误,将不胜感激任何帮助!
编辑:这是我检索“日志”列表的方式:
getLogList(): Observable<any> {
return new Observable((observer: any) => {
let path = 'Logs';
let onValueEvent = (snapshot: any) => {
this.ngZone.run(() => {
let results = this.handleSnapshot(snapshot.value);
console.log(JSON.stringify(results))
observer.next(results);
});
};
firebase.addValueEventListener(onValueEvent, `/${path}`);
}).share();
}