繁体   English   中英

JavaScript:提醒我的实时数据库中的特定值

[英]JavaScript: alerting a specific value on my real-time database

我一直在努力实现以下目标,但我做不到

这是我的快照数据: 屏幕

如果我想提醒ada的名字,我应该使用什么代码?

我用这个,它返回未定义的:

    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);
  });

但这没用,有什么建议吗?

错误图片: SCE

注意:JavaScript全新

文档中 ,它是

// key will be "ada" the first time and "alan" the second time
var key = childSnapshot.key;

不是var key = childSnapshot.key.val;

暂无
暂无

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

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