【发布时间】:2020-08-01 07:17:56
【问题描述】:
我创建了一个使用 UID 将数据发送到 firebase 的函数。数据显示在带有 UID 和项目 ID 的 firebase 中。如果用户登录,我可以检索数据,但我对如何获取具有唯一自动生成 ID 的项目的特定节点子节点的路径感到困惑。
// Data stored in firebase
"profiles" : {
// UID
"SUFbOOK4XvPNIaQqIjJ2ey6ziDF3" : {
//Item ID
"-M54AgiUdxYEmu20Yau0" : {
//childs
"eau" : "111111",
"edan" : "22222",
"image" : "0625594",
"nom" : "hello",
"prenom" : "world",
"profession" : "Dev",
"solde" : "100000",
"telephone" : "06255444794"
}
}
这是该数据库在 userID 之前的路径引用。
this.reference = firebase.database().ref('profiles/'+this.afAuth.auth.currentUser.uid);
这是向 Firebase 发送数据的函数
create(nom,telephone,edan,prenom,profession,eau,solde){
this.imageName = telephone;
let loading = this.load.create({
content: 'Veuillez patienter ...'
});
loading.present();
setTimeout(() => {
loading.dismiss();
this.afAuth.authState.take(1).subscribe(auth => {
this.af.list(`profiles/${auth.uid}`).push({
nom: nom,
edan: edan,
eau: eau,
prenom: prenom,
profession: profession,
telephone: telephone,
solde: solde,
image:this.imageName,
}).then (() =>
this.navCtrl.push('LoginPage')
)
})
}, 2500);
this.upload()
}
如何使用 UID 获取 Firebase 中列表的唯一项 ID 的参考路径?
【问题讨论】:
标签: javascript firebase firebase-realtime-database angularfire2