【问题标题】:Get All Items from Firebase using angularfire2使用 angularfire2 从 Firebase 获取所有项目
【发布时间】:2019-11-07 23:51:52
【问题描述】:

我开发了一个跟踪应用程序,它运行良好,当用户想要跟踪某些特定车辆时,他选择了该车辆并且我的应用程序显示了它的位置,现在我想显示所有实时车辆,我面临的问题是我我无法从火力基地获得所有车辆。谁能帮我做这件事。

/** Function to get firebase DB list for vehNumber*/
public getList(vehNumber): AngularFireList<{}> {
this.vehRef = this._db.list(vehNumber);
return this.vehRef;
}

我想在不传递任何参数的情况下获取所有存在于 firebase 中的车辆,但它在要求参数时给出错误:

public getList(): AngularFireList<{}> {
this.vehRef = this._db.list();
return this.vehRef;
}

【问题讨论】:

标签: typescript firebase firebase-realtime-database angularfire2


【解决方案1】:

如果你有以下数据库:

activeVehicles
          randomId1 
               vehicle: vehicle1
          randomId2 
               vehicle: vehicle2

然后您可以执行以下操作来获得所有活车:

this.firebase.list('/activeVehicles').valueChanges().subscribe(active => 
{
   console.log(active);  
     items.forEach(vehicles =>
     { 
        console.log(vehicles) ;
     });
});

vehicles 将包含数据库中的所有活动车辆。

【讨论】:

  • 我的数据库看起来像:prntscr.com/o6rwk5 因为车辆编号是它自己的节点
  • 你要检索车号吗?
  • 这样做this.firebase.list().valueChanges().subscribe(active =&gt; { console.log(active); items.forEach(vehicles =&gt; { console.log(vehicles) ; }); });
猜你喜欢
  • 2018-07-28
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多