使用angularfire2从Firebase获取所有项目

时间:2019-06-26 05:42:49

标签: typescript firebase firebase-realtime-database angularfire2

我开发了一个跟踪应用程序,它的运行状况很好,当用户要跟踪某些特定的车辆时,他选择了该车辆,而我的应用程序显示了它的位置,现在我想显示所有带电车辆,我面临的问题是我我无法从火力基地获得所有车辆。有谁能帮我实现这一目标吗?

_id:5d0c9f38082276944579ba3e
user_Name:"Mark"
rows:[
{
   project_ID:"xxxx"
   issue_Summary:"aaaa"
   short_Description:"aaaa"
   start_Time:"02:02"
   end_Time:"03:02"
   total_Time:""
   _id:5d0ca14e138a7628948804af
   date:2019-06-21 05:30:00.0001
}
{
   project_ID:"yyyy"
   issue_Summary:"bbb"
   short_Description:"bbb"
   start_Time:"02:02"
   end_Time:"03:02"
   total_Time:""
  _id:5d0ca14e138a7628948804af
  date:2019-06-21 05:30:00.0001
}
]

 _id:5d0c9f38082276944579ba3e
user_Name:"Mark"
rows:[
{
   project_ID:"xxxx"
   issue_Summary:"aaaa"
   short_Description:"aaaa"
   start_Time:"02:02"
   end_Time:"03:02"
   total_Time:""
   _id:5d0ca14e138a7628948804af
   date:2019-06-22 05:30:00.0001
}
{
   project_ID:"yyyy"
   issue_Summary:"bbb"
   short_Description:"bbb"
   start_Time:"02:02"
   end_Time:"03:02"
   total_Time:""
  _id:5d0ca14e138a7628948804af
  date:2019-06-22 05:30:00.0001
}
]

_id:5d0c9f38082276944579ba3e
user_Name:"Dany"
rows:[
{
   project_ID:"xyz"
   issue_Summary:"aaaa"
   short_Description:"aaaa"
   start_Time:"02:02"
   end_Time:"03:02"
   total_Time:""
   _id:5d0ca14e138a7628948804af
   date:2019-06-21 05:30:00.0001
}
{
   project_ID:"yzx"
   issue_Summary:"bbb"
   short_Description:"bbb"
   start_Time:"02:02"
   end_Time:"03:02"
   total_Time:""
  _id:5d0ca14e138a7628948804af
  date:2019-06-21 05:30:00.0001
}
]

我想获得所有在firebase中生活的车辆,而不传递任何参数,但由于要求参数,它给出了错误:

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

1 个答案:

答案 0 :(得分:0)

如果您具有以下数据库:

activeVehicles
          randomId1 
               vehicle: vehicle1
          randomId2 
               vehicle: vehicle2

然后,您可以执行以下操作获得所有带电车辆:

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

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