我希望每个日期下的每个对象都位于Firebase数据库中的费用类别下。Angularfire2 - 检索对象中的所有值而不引用父对象的键?
在火力地堡:
- expenses
- food
- 07-11-2016 //"I want every object in here"
+ -KX7Aju4_G6i6pcNoBzj
在我看来,我已经试过:
<div *ngFor="let date of food | async">
<ion-item-divider sticky>
{{date.$key}}
</ion-item-divider>
<div *ngFor="let item of date"> //This don't seem to work
<ion-item>
<h3>{{item.title}}</h3>
<p>
{{item.amount}} Kr —
kl. {{item.time}}
</p>
</ion-item>
</div>
</div>
FIREBASE WARNING: Exception was thrown by user callback. Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
显然,它给我的日期为对象,而不是一个数组。我也尝试检索JSON中的值,但用* ngFor(与管道异步)迭代JSON对象也给我一堆问题。
/* Returns a Firebase list object as a JSON object */
getAsJSON(firebaseList: any){
firebaseList
.map(obj => obj.map(obj => {
return obj;
}));
}
我想迭代火力列表对象“食物”。
this.food = af.database.list('/expenses/food');
OR
this.food_json = getAsJSON(this.food);
我已阅读并尝试了一堆,但我似乎无法找到合适的解决方案。
对于你第二ngFor需要变换对象阵列,使用管为该。好的答案在这里:http://stackoverflow.com/questions/35647365/how-to-display-json-object-using-ngfor/35647396#35647396 – Yevgen
谢谢@Yevgen会着眼于它。 –