繁体   English   中英

使用 Ionic 获取 Firebase 中唯一项目 ID 的参考路径

[英]Get the reference path of unique Item Id in Firebase using Ionic

我制作了一个 function 使用 UID 将数据发送到 firebase。 数据出现在 firebase 中,带有 UID 和项目 ID。 如果用户登录,我可以检索数据,但我对如何获取具有唯一自动生成 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);

这里是 function 发送数据到 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 的参考路径?

我想你正在寻找这个:

reference.once("value", function(snapshot) {
  console.log(snapshot.key); // "SUFbOOK4XvPNIaQqIjJ2ey6ziDF3"
  snapshot.forEach(function(child) {
    console.log(child.key); // "-M54AgiUdxYEmu20Yau0"
    console.log(child.val().nom); // "hello"
    child.child("nom").ref.update("world");
  })
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM