我一直在努力实现以下目标,但我无法
如果我想提醒 ada 的第一个名字,我应该使用哪些代码?
我用过它,它返回undefined:
if (user) {
// User is signed in.
alert('user signed')
// Get a reference to the database service
var database = firebase.database();
var query = firebase.database().ref("users");
query.once("value")
.then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
// key will be "ada" the first time and "alan" the second time
var key = childSnapshot.key.val;
// childData will be the actual contents of the child
var childData = childSnapshot.val();
alert(key);
});
但它没有用,有什么建议吗?
注意:全新的JavaScript
答案 0 :(得分:1)
,它是
// key will be "ada" the first time and "alan" the second time
var key = childSnapshot.key;
不是var key = childSnapshot.key.val;