2016-10-29 4 views
4

Ich habe ein JSON-Array wie folgt;Erstellen einer dynamischen Liste mit JSON-Antwort

"collectings": [ 
    { 
     "hint": "OPEN", 
     "amount": 24 
    }, 
    { 
     "hint": "CREDIT CARD", 
     "amount": 347 
    }, 
    { 
     "hint": "CASH", 
     "amount": 256.5 
    } 
    ] 

Jetzt möchte ich diese Daten auf einer Liste dynamisch anzeigen, ich versuche es wie folgt zu tun;

<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> 

aber es wird auf der Seite wie dem folgenden Bild angezeigt; enter image description here Wie kann ich es richtig anzeigen?

Antwort

2

Statt {{ collectings }} (das ist der Array)

<ion-item *ngFor="let collecting of collectings">{{collectings}}</ion-item> 

Sie die collecting Eigenschaft gedruckt werden soll (ohne die Endung s) und verwenden Sie die hint oder amount Untereigenschaften wie folgt aus:

<ion-item *ngFor="let collecting of collectings"> 
    {{collecting.hint}} - {{ collecting.amount }} 
</ion-item> 
+0

@sebaferreas Ich habe es schon probiert aber wenn ich das mache zeigt es nichts an. Ich habe bereits überprüft, dass das Array leer ist oder nicht mit dem ngIf-Teil, weil ich Array als Antwort vom Rest bekomme und es an mein Array binde. – cano

+1

@sebaferreas ja du hast recht. Ich druckte die Sammlungen. Nun, es funktioniert – cano

+0

Großartig, froh zu hören, dass Sie das Problem gelöst haben :) – sebaferreras

Verwandte Themen