2017-01-06 2 views
0

Ich möchte Through meine JSON-Array. Die Jsons ist:Ionic 2 Loop-Through-JSON Von Rest Service

{ 
 
    "0": { 
 
    "id": "678", 
 
    "name": "Several Definitions (VD) - Podcast 104 - ubwg.ch", 
 
    "artist": { 
 
     "id": "282", 
 
     "name": "Unsere Beweggründe (CH)", 
 
     "soundcloudId": 3473917, 
 
     "facebookId": null 
 
    }, 
 
    "day": "2017-01-06", 
 
    "soundcloudTrackId": "277888181" 
 
    }, 
 
    "1": { 
 
    "id": "677", 
 
    "name": "Maedchenhouse Vol. 13", 
 
    "artist": { 
 
     "id": "1089", 
 
     "name": "maedchenhouse", 
 
     "soundcloudId": 73887525, 
 
     "facebookId": null 
 
    }, 
 
    "day": "2017-01-05", 
 
    "soundcloudTrackId": "192561213" 
 
    }, 
 
    "hasAnother": true 
 
}

Hier ist meine ionische html-Datei:

<ion-grid *ngFor="let set of sets"> 
 
    <ion-card> 
 
     <img src="https://i1.sndcdn.com/artworks-000174566284-nngazk-t300x300.jpg"/> 
 
     <ion-card-content> 
 
     <ion-card-title> 
 
     {{set.name}} 
 
      </ion-card-title> 
 
     <p> 
 
      The most popular industrial group ever, and largely 
 
      responsible for bringing the music to a mass audience. 
 
     </p> 
 
     </ion-card-content> 
 
    </ion-card> 
 
    </ion-grid>

Und das ist, wie ich es analysieren:

public generateSets(data){ 
 
    \t this.sets = JSON.parse(data); 
 
    \t alert(this.sets[0].name); 
 
    }

Btw die Benachrichtigung funktioniert, aber ich weiß nicht, wie das Netz in meiner ionischen HTML-Datei zu aktualisieren. Auch {{set [0] .name}} ohne eine Schleife funktioniert nicht. Hat jemand eine Idee? Grüße

Antwort

0

Sie benötigen ein Array in Ihrer Vorlage. Also wandle dein JSON-Objekt in ein Array um.

sets_array = Object.keys(this.sets).map(function (key) { return this.sets[key]; }); 

Dann verwenden Sie es in Vorlage.