例如,我是这样设置数据的:
var usersRef = firebase.database().ref("userlist/");
usersRef.child(nickname).set({
userid: id,
email: email,
});
如果以后我想收到昵称为的电子邮件,我应该怎么做?为什么我不能这样做:
const email =usersRef.child(nickname).child(email);
发布于 2018-08-10 08:36:24
要获取电子邮件,您需要执行以下操作:
var ref = firebase.database().ref("userlist").child(nickname);
ref.on("value", function(snapshot) {
let emails=snapshot.val().email;
console.log(email);
});
});
您需要引用该位置,然后将监听器附加到该位置,以便能够检索子值,如email
和id
发布于 2018-08-10 08:37:52
您设置的email
常量并不指向电子邮件,而是指向firebase数据库引用。
要获取电子邮件的值,您需要监听引用,该值等于返回的值。
ref.child(nickname).child("email").on("value", function(snapshot) {
const email = snapshot.val();
});
https://stackoverflow.com/questions/51782251
复制相似问题