Angularfire无法检索密钥

时间:2018-02-07 19:27:54

标签: firebase firebase-realtime-database angularfire angularfire2

我这里有这个代码块;

 return this.db.list(`users/${currentId}/chatThreads/`)
      .map((thread) => {
        thread.map((t) => {
          let x = {
            key: t, // <- Undefined? Where's the key
            count: t.$value,
          }
          console.log(x);
          return x;
        })
      });

chatThreads看起来像这样 enter image description here

尝试将此对象转换为上面的简单键值JSON(使用x)。但是,我可以使用值1来计算,但键是未定义的。

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

return this.db.list(`users/${currentId}/chatThreads/`)
      .snapshotChanges()
      .map((thread) => {
        thread.map((t) =>
          return t.map(c => ({ key: c.payload.key, ...c.payload.val() 
     })
        })
      });
相关问题