简体   繁体   中英

Complex json ng-repeat

I try to ng-repeat on this object, I tried several times but still stuck. If anyone have an idea, and if it's possible to share tips for this kind of situation.

[
{
    "Abonnement": {
        "id": "1",
        "nom": "BAS PRIX",
        "tarif": "2.49",
        "communication": "2h de communication",
        "vers": "vers fixes et mobiles",
        "zone": "zone nationale"
    }
},
{
    "Abonnement": {
        "id": "2",
        "nom": "NATIONAL",
        "tarif": "9.99",
        "communication": "t\u00e9l\u00e9phonie et SMS illimit\u00e9s",
        "vers": "vers fixes et mobiles",
        "zone": "zone nationale"
    }
},
{
    "Abonnement": {
        "id": "3",
        "nom": "EURO",
        "tarif": "19.99",
        "communication": "t\u00e9l\u00e9phonie et SMS illimit\u00e9s",
        "vers": "vers fixes et mobiles",
        "zone": "zone EURO"
    }
}
]

If the array is stored in the scope under $scope.abonnements , this is how you would use ng-repeat :

<ul>
  <li ng-repeat="item in abonnements">{{ item.Abonnement.nom }}</li>
</ul>

See here: http://jsfiddle.net/89b98cpd/

Assuming you have name your object something like Abonnements

  $scope.Abonnement = [..your example json]

Then you'd just use the ng-repeat like

  <div ng-repeat="Abonnement in Abonnements">
      id: {{Abonnement.Abonnement.id}}
  </div>

And access the information with Abonnement.Abonnement.id for example. So if you wanted the vers, it would be Abonnement.Abonnement.vers .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM