【问题标题】:Angularfire not able to retrieve keyAngularfire无法检索密钥
【发布时间】:2018-02-07 19:27:53
【问题描述】:

我这里有这个代码块;

 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 看起来像这样

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

我在这里错过了什么?

【问题讨论】:

  • 不是this.db.list(users/${currentId}/chatThreads/).valueChanges().map()吗?
  • 这是 angularfire.. 我不认为 valueChanges() 存在..(顺便说一句,这不是实时数据库)

标签: firebase firebase-realtime-database angularfire angularfire2


【解决方案1】:
return this.db.list(`users/${currentId}/chatThreads/`)
      .snapshotChanges()
      .map((thread) => {
        thread.map((t) =>
          return t.map(c => ({ key: c.payload.key, ...c.payload.val() 
     })
        })
      });

【讨论】:

猜你喜欢
  • 2015-08-22
  • 2018-08-21
  • 2011-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-20
相关资源
最近更新 更多