我有一个Firebase数据库,其中包含要从用户检索的数组数据。具体而言,addnote
,其中信息Du the dishes
。作为参考,我已经包含了我的数据库的图像。从Firebase中检索用户数组
我的JSON格式DB。我试图削减多余的部分是考虑我的胡闹:
{
"items" : {
"-KSm_hb4Rw4rudtjxq6x" : {
"addnote" : "Red"
},
"-KSmc45MdhuXIkNkoiN-" : {
"addnote" : "Red"
},
"-KSmc8ZsUDGb23MapKl9" : {
"addnote" : "Red"
}
},
"users" : {
"PYuSE6zyAENdKREZGTHm5VH1DXn1" : {
"addnote" : {
"-KSnELpl7-dkmjlyGl2x" : "Du the dishes",
"-KSnFBaM4VXOyFTjWtaE" : "Du the dishes",
"-KSnFDlC9hND-M3C2pWE" : "Du the dishes"
},
"useremail" : "[email protected]",
"username" : "asdasd"
},
"ag1ZF6Z4cEZ5AsvusiSD9Z1WyUn2" : {
"useremail" : "[email protected]",
"username" : "jaconb"
}
}
}
我想知道,这样它收到关于我的addnote
项目如何重新安排我的构造函数的代码的用户。
constructor(af: AngularFire){
this.addsnotes = af.database.list('users/' + addnote);//should fetch my notes.
}
addSubmit(){
var self = this;
var user = firebase.auth().currentUser;
var getUserInfo = firebase.database().ref('users/' + user.uid);
if (user){getUserInfo.child('addnote').push("Du the dishes");}
}
下面是我想打印出来的HTML:
<li *ngFor="let addsnote of addsnotes | async">{{ addnote }}</li>
编辑:修正我的代码。将li
更改为拨打{{addnote}}
,以便通话正常工作。但是,我在我的数组上得到一个[对象对象]。
export class ProfileComponent implements OnInit {
private username: string;
private addsnotes: FirebaseListObservable<any>;
constructor(af: AngularFire){
var user = firebase.auth().currentUser;
this.addsnotes = af.database.list('users/'+user.uid+'/addnote');
}
ngOnInit(){
var self = this;
}
addSubmit(){
var self = this;
var user = firebase.auth().currentUser;
var getUserInfo = firebase.database().ref('users/' + user.uid);
if (user){
getUserInfo.child('addnote').push("Du the dishes");
}
}
}
你已经包括了JSON树在你的问题的照片。请用实际的JSON替换为文本,您可以通过点击Firebase数据库控制台中的导出按钮轻松获取。将JSON作为文本可以搜索,使我们能够轻松使用它来测试您的实际数据,并将其用于我们的答案中,并且通常只是一件好事。 –