繁体   English   中英

Firebase / Angularfire2:firebase中的嵌套数据节点

[英]Firebase / Angularfire2: nested data nodes in firebase

我有一个Firebase数据库。 名为/ config //的节点,用于保存用户特定的数据。 我现在想在子数据中添加带有汽车列表的子树,例如/ config // cars /:

"config" : {
    "NE5AwHcxKofMPKRCAvny5Re4MtG3" : {
      "geburtstag" : "2017-06-04",
      "nachname" : Mueller",
      "cars" : {
        "-Krr2-DC1uoqCvgVJhFL" : {
          "name" : "Ford Mustang"
        },
        "-Krue4_5kJQhis-3Qg1X" : {
          "name" : "Toyota Supra"
        }
      }
    }

我创建了一个可观察的绑定到/ config /

this.$ref = this.database.object('/config/' + uid);
this.data = this.$ref.subscribe();

我可以访问主配置节点的数据并将其与angular绑定,但是Cars子节点上的ngFor不起作用。 我是在错误构造数据还是在这里需要某种映射?

html部分:

 <ion-item *ngFor="let car of data.cars | async"> {{car.name}} </ion-item> 

您正在将data分配给订阅,而应该将data分配给可观察的对象:

cars: FirebaseListObservable<any[]>;
this.cars = this.database.list(`/config/${uid}/cars`);

现在,您可以在ngFor循环中调用async数据:

<ion-item *ngFor="let car of cars | async">
  {{ car.name }}
</ion-item>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM