Javascript firebase PushID环

Javascript firebase PushID环,javascript,firebase,ionic-framework,firebase-realtime-database,Javascript,Firebase,Ionic Framework,Firebase Realtime Database,我正在尝试循环数据库并返回“eventList”中与当前用户ID匹配的所有事件。我这里的问题是,我很难简单地返回一个posted的列表。结果我要么得到“事件列表”要么得到“未定义”。如何循环数据库并返回“事件列表”下的postID 我有以下数据库结构: { "eventList" : { "-LQ68rGmj_OYShda3tV9" : { "name" : "Christmas", "user" : "8eZcncLHPCWtuuhw90HRr79f0VO2

我正在尝试循环数据库并返回“eventList”中与当前用户ID匹配的所有事件。我这里的问题是,我很难简单地返回一个posted的列表。结果我要么得到“事件列表”要么得到“未定义”。如何循环数据库并返回“事件列表”下的postID

我有以下数据库结构:

{
  "eventList" : {
    "-LQ68rGmj_OYShda3tV9" : {
      "name" : "Christmas",
      "user" : "8eZcncLHPCWtuuhw90HRr79f0VO2"
    },
      "-L23Tr87ejdjh9osnG" : {
      "name" : "easter",
      "user" : "7gjsuhv84mvkkslv0jlssvghdasd"
    }

  },
  "userProfile" : {
    "8eZcncLHPCWtuuhw90HRr79f0VO2" : {
      "firstName" : "M"
    }
  }
}
以下是我一直使用的代码:

this.postRef = firebase.database().ref('/eventList');
this.postRef.once("value")
  .then(function(snapshot) {
    var key = snapshot.key; // null


  });
  console.log(this.postRef.key);

尝试在节点内部循环并获取每个值,同时打印承诺内的数据,因为
。一旦
处理异步工作,并且如果尝试在
外部获取密钥,则
将为空,如果承诺失败,还将处理捕获错误

 this.postRef = firebase.database().ref('/eventList');
    this.postRef.once("value")
      .then(function(snapshot) {

     const eventData = snapshot.forEach(data => {
     var key = data.key; 
     console.log(this.postRef.key);
      });

     return eventData;

 }).catch(error => {
         console.log('Error trying to fetch the data.');
        });

对不起,我弄糊涂了。您不应该在
控制台.log
。然后(function(){…})
这个.postRef.key
不是指向快照的键吗?是的,我的一个错误