首页 > 解决方案 > 从 FIrebase 实时数据库中获取数据

问题描述

例如,这是我设置数据的方式:

var usersRef = firebase.database().ref("userlist/");
usersRef.child(nickname).set({
    userid: id,
    email: email,
    });

如果我以后想收到给定昵称的电子邮件,我该怎么办?为什么我不能这样做:

const email =usersRef.child(nickname).child(email);

标签: javascripthtmldatabasefirebasefirebase-realtime-database

解决方案


要获取电子邮件,您需要执行以下操作:

 var ref = firebase.database().ref("userlist").child(nickname);

ref.on("value", function(snapshot) { 
   let emails=snapshot.val().email;
    console.log(email);
  });
});

您需要引用该位置,然后将侦听器附加到它,以便能够检索子值,例如emailid


推荐阅读