我有一个像以下一样的json数组;
"collectings": [
{
"hint": "OPEN",
"amount": 24
},
{
"hint": "CREDIT CARD",
"amount": 347
},
{
"hint": "CASH",
"amount": 256.5
}
]
现在,我想动态地在列表中显示这些数据,我试着像下面这样做;
<ion-content>
<div class="row" *ngIf="collectings && collectings.length > 0">
<ion-list>
<ion-list-header>Comedy</ion-list-header>
<ion-item *ngFor="let collecting of collectings">{{collectings}}</ion-item>
</ion-list>
</div>
</ion-content>
答案 0 :(得分:3)
而不是{{ collectings }}
(这是数组)
<ion-item *ngFor="let collecting of collectings">{{collectings}}</ion-item>
你应该打印collecting
属性(没有结尾s)并使用hint
或amount
子属性,如下所示:
<ion-item *ngFor="let collecting of collectings">
{{collecting.hint}} - {{ collecting.amount }}
</ion-item>