2017-04-08 2 views
1

Ich habe einige JSON-Daten, die ich in eine Liste mit Sub-Listen innerhalb der Daten geladen habe. die JSON-Daten aus einer API gezogen unter Verwendung einesng-repeat innerhalb eines anderen ng-repeats

 "pet": [ 
 
     { 
 
      "options": { 
 
      "option": [ 
 
       { 
 
       "$t": "hasShots" 
 
       }, 
 
       { 
 
       "$t": "altered" 
 
       }, 
 
       { 
 
       "$t": "housetrained" 
 
       } 
 
      ] 
 
      }, 
 
      "status": { 
 
      "$t": "A" 
 
      }, 
 
      "contact": { 
 
      "phone": { 
 
       "$t": "emails only please" 
 
      }, 
 
      "state": { 
 
       "$t": "NC" 
 
      }, 
 
      "address2": { 
 
       
 
      }, 
 
      "email": { 
 
       "$t": "[email protected]" 
 
      }, 
 
      "city": { 
 
       "$t": "Charlotte" 
 
      }, 
 
      "zip": { 
 
       "$t": "28226" 
 
      }, 
 
      "fax": { 
 
       
 
      }, 
 
      "address1": { 
 
       
 
      } 
 
      }, 
 
      "age": { 
 
      "$t": "Senior" 
 
      }, 
 
      "size": { 
 
      "$t": "M" 
 
      }, 
 
      "media": { 
 
      "photos": { 
 
       "photo": [ 
 
       { 
 
        "@size": "pnt", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=60&-pnt.jpg", 
 
        "@id": "1" 
 
       }, 
 
       { 
 
        "@size": "fpm", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=95&-fpm.jpg", 
 
        "@id": "1" 
 
       }, 
 
       { 
 
        "@size": "x", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=500&-x.jpg", 
 
        "@id": "1" 
 
       }, 
 
       { 
 
        "@size": "pn", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=300&-pn.jpg", 
 
        "@id": "1" 
 
       }, 
 
       { 
 
        "@size": "t", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/1\/?bust=1475677088&width=50&-t.jpg", 
 
        "@id": "1" 
 
       }, 
 
       { 
 
        "@size": "pnt", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=60&-pnt.jpg", 
 
        "@id": "2" 
 
       }, 
 
       { 
 
        "@size": "fpm", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=95&-fpm.jpg", 
 
        "@id": "2" 
 
       }, 
 
       { 
 
        "@size": "x", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=500&-x.jpg", 
 
        "@id": "2" 
 
       }, 
 
       { 
 
        "@size": "pn", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=300&-pn.jpg", 
 
        "@id": "2" 
 
       }, 
 
       { 
 
        "@size": "t", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/2\/?bust=1475677088&width=50&-t.jpg", 
 
        "@id": "2" 
 
       }, 
 
       { 
 
        "@size": "pnt", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=60&-pnt.jpg", 
 
        "@id": "3" 
 
       }, 
 
       { 
 
        "@size": "fpm", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=95&-fpm.jpg", 
 
        "@id": "3" 
 
       }, 
 
       { 
 
        "@size": "x", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=500&-x.jpg", 
 
        "@id": "3" 
 
       }, 
 
       { 
 
        "@size": "pn", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=300&-pn.jpg", 
 
        "@id": "3" 
 
       }, 
 
       { 
 
        "@size": "t", 
 
        "$t": "http:\/\/photos.petfinder.com\/photos\/pets\/36298811\/3\/?bust=1475677088&width=50&-t.jpg", 
 
        "@id": "3" 
 
       } 
 
       ] 
 
      } 
 
      }, 
 
      "id": { 
 
      "$t": "36298811" 
 
      }, 
 
      "shelterPetId": { 
 
      "$t": "Domino" 
 
      }, 
 
      "breeds": { 
 
      "breed": { 
 
       "$t": "Domestic Medium Hair" 
 
      } 
 
      }, 
 
      "name": { 
 
      "$t": "Domino" 
 
      }, 
 
      "sex": { 
 
      "$t": "M" 
 
      }, 
 
      "description": { 
 
      "$t": "Domino is a sweet, talkative kitty with lots of purr-sonality. He never meets a stranger, and will let children carry him around in their arms. \nHe has tested positive for FIV, but we have had him in our rescue since 2009, and he has never had any health problems at all. He is neutered and up to date on vaccinations.We think he was born around 2005-2006. Must be an indoor only cat. He has had regular dental cleanings; last one was April of 2015. He would make a great companion for anyone who wants an affectionate kitty to love and care for." 
 
      }, 
 
      "mix": { 
 
      "$t": "no" 
 
      }, 
 
      "shelterId": { 
 
      "$t": "NC773" 
 
      }, 
 
      "lastUpdate": { 
 
      "$t": "2017-03-15T12:37:11Z" 
 
      }, 
 
      "animal": { 
 
      "$t": "Cat" 
 
      } 
 
     }   
 
     ] 
 

und mein Code

<ol><li ng-repeat="pet in pets | orderBy: 'name.$t'"> 
 
<div>{{pet.name.$t}} - {{pet.animal.$t}}</div> 
 
<div ng-repeat="pic in pet.photo">{{pic.$t}}</div> 
 
</li> 
 
<ul></ul> 
 
</ol>

und Haustiere Anruf eingeht = über die JSON-Daten. Die erste ng-Wiederholung funktioniert gut, die zweite, die in der ersten verschachtelt ist, funktioniert nicht. ursprünglich hatte ich es in einem img-Tag als ng-src und ich dachte, es hätte etwas mit dem $ sce-Quellschutz zu tun, aber das funktioniert auch nicht, so dass es nicht der Fall zu sein scheint

+0

Konnten Sie genauer sein? Was meinst du mit "geht nicht"? Was hast du versucht? Was ist das Ergebnis, das du jetzt hast? Was ist das Ergebnis, das Sie erwartet haben? – Sorikairo

+0

Ich habe gerade getestet, ob ich die Liste der Fotos richtig zurückgeben kann. Irgendwann würde ich eine Galerie haben, durch die man navigieren konnte, aber ich merkte, dass ich meine Arrays durcheinander gebracht hatte. – Walt

Antwort

2

Sie sind fehlt der Medientyp

<ol><li ng-repeat="pet in pets | orderBy: 'name.$t'"> 
<div>{{pet.name.$t}} - {{pet.animal.$t}}</div> 
<div ng-repeat="pic in pet.media.photos.photo">{{pic.$t}}</div> 
</li> 
<ul></ul> 
</ol> 
+0

Danke, ich hatte es so, aber ich bemerkte auch, dass ich es als pet.media.photos hatte und es pet.media.photos.photo sein musste. Ich bin ein Idiot – Walt

Verwandte Themen