Firebase/Angularfire2:firebase中的嵌套数据节点 [英] Firebase / Angularfire2: nested data nodes in firebase
问题描述
我有一个firebase数据库.一个名为/config//的节点,用于保存用户特定的数据.我现在想向用户数据添加带有汽车列表的子树,例如/config//cars/:
i've got a firebase database. a node called /config// which holds userspecific data. i now want to add a subtree to the userdata with a list of cars, like /config//cars/:
"config" : {
"NE5AwHcxKofMPKRCAvny5Re4MtG3" : {
"geburtstag" : "2017-06-04",
"nachname" : Mueller",
"cars" : {
"-Krr2-DC1uoqCvgVJhFL" : {
"name" : "Ford Mustang"
},
"-Krue4_5kJQhis-3Qg1X" : {
"name" : "Toyota Supra"
}
}
}
我创建了一个可观察到的/config/绑定
i created a observable binding to /config/
this.$ref = this.database.object('/config/' + uid);
this.data = this.$ref.subscribe();
我可以访问主配置节点的数据并将其与angular绑定,但是Cars子节点上的ngFor不起作用.我是在错误构造数据还是在这里需要某种映射?
i can access the data of the main config-node and bind it with angular, but a ngFor on the Cars subnode doesn't work. Am i structuring my data wrong or do I need some kind of mapping here?
html部分:
<ion-item *ngFor="let car of data.cars | async">
{{car.name}}
</ion-item>
推荐答案
您正在将data
分配给您的订阅,而您应该将其分配给可观察的对象:
You're assigning data
to your subscription while you should be assigning it to the observable:
cars: FirebaseListObservable<any[]>;
this.cars = this.database.list(`/config/${uid}/cars`);
现在,您可以在ngFor
循环中调用async
数据了:
Now you can call your async
data in your ngFor
loop:
<ion-item *ngFor="let car of cars | async">
{{ car.name }}
</ion-item>
这篇关于Firebase/Angularfire2:firebase中的嵌套数据节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!