【问题标题】:Get firebase data from several indexes (nodes)从多个索引(节点)获取 firebase 数据
【发布时间】:2018-02-18 08:48:49
【问题描述】:

这是我的数据库示例:

目标是列出节点 1 中用户的所有待定约会。然后在节点 2 中检索此约会的一些数据,尤其是 praticien Id,以最终获取有关该 praticien 的所有详细信息。 我可以使用以下代码将我的数据从 1 号映射到 2 号:

idPatient: string
  pendingAppointment: any
  noConnection: boolean
  constructor(public navCtrl: NavController, public navParams: NavParams, public network: NetworkProvider, public firebaseProvider: FirebaseServiceProvider) {
    this.idPatient = this.navParams.get('user')
      this.pendingAppointment = this.firebaseProvider.list('patientList/'+this.idPatient+'/appointments/pending')
      .map(appointments => {
        return appointments.map(appointment => {
        return  this.firebaseProvider.object('appointments/' + appointment.$key )
        })
      })

..并使用以下命令获取我的 html 中的数据:

<div *ngFor="let appointment of pendingAppointment | async;let i = index">
{{ (appointment | async)?.praticien }}
        </div>

但我被这个愚蠢的问题困住了。 如何映射 3 号节点并在 html 中检索 3 号节点的详细信息?

也许有人可以帮助我。

【问题讨论】:

    标签: typescript firebase firebase-realtime-database ionic3 angularfire


    【解决方案1】:

    我认为这样的事情应该可以工作......

    this.pendingAppointment = this.db.list('patientList/'+this.idPatient+'/appointments/pending').snapshotChanges().map(appointments => {
        return appointments.map(appointment => ({
          appointments: this.db.object('appointments/' + appointment.payload.key).valueChanges().map(
            app => ({
              place: this.db.object('practiciensDetails/' + app.practicien).valueChanges()
            })
          )
        }));
      });
    

    然后对于您的 html,如下所示:

    <div *ngFor="let appointment of pendingAppointment | async;let i = index">
      {{ (appointment | async)?.praticien }}
      {{ ((appointment | async)?.place | async)?.firstname }}
    </div>
    

    希望这会有所帮助!经过几个小时的摆弄,我能够在我的项目中得到与此类似的东西。我记得我花了好几天的时间才迈出了两个层次的第一步。在这种情况下,第三级实际上只归结为“映射”对象而不是列表的语法,这让我永远找不到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-07
      • 2017-10-12
      • 1970-01-01
      • 2021-12-16
      • 2019-01-03
      • 2020-05-05
      • 1970-01-01
      • 2019-01-02
      相关资源
      最近更新 更多