【问题标题】:Ionic: Can't loop through all firebase records离子:不能遍历所有的火力基地记录
【发布时间】:2017-12-29 18:56:02
【问题描述】:

我的主要目标是遍历firebase中请求表中的所有记录以获取用户键值。当我遍历所有记录时,我只得到表中的第一条记录。

我的代码:

openMapPage()
  {

     this.request.forEach(i => {
     let r = 0;
     console.log(i[r].$key);
     r++ 
   });

  this.navCtrl.push(MapPage)

   }

我的控制台只打印 1 个用户键值:

我的 Firebase 数据库:

【问题讨论】:

标签: firebase ionic-framework firebase-realtime-database ionic2


【解决方案1】:

可能您的“this.request”指向父对象。试试这个:

let process = this.request.subscribe(records => {
// your logic
 records.forEach(record => {
  console.log(record.$key);
 });

});
// Remove watch if you wish
process.unsubscribe();

【讨论】:

  • 不,它没有
  • this在构造函数处,this.request = angFire.list('/request');
  • 您确定您的 firebase 配置指向正确的数据库吗?
猜你喜欢
  • 2018-03-27
  • 1970-01-01
  • 2017-12-21
  • 2016-09-17
  • 2017-11-20
  • 2016-12-11
  • 2018-06-25
  • 2020-11-25
  • 1970-01-01
相关资源
最近更新 更多