[英]JavaScript: alerting a specific value on my real-time database
I've been trying to achieve the following, but I couldn't 我一直在努力实现以下目标,但我做不到
and here is my snapshot data: 这是我的快照数据:
If I wanted to alert ada's first name, what code should i use? 如果我想提醒ada的名字,我应该使用什么代码?
I used this, it returns 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);
});
but it didn't work, any suggestions? 但这没用,有什么建议吗?
note: completely new to JavaScript
注意:JavaScript全新
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.