簡體   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