复杂的json ng-repeat

时间:2015-06-25 15:33:50

标签: javascript json angularjs angularjs-ng-repeat

我尝试对这个物体进行重复,我试了好几次但仍然卡住了。如果有人有想法,并且可以分享这种情况的提示。

[
{
    "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"
    }
}
]

2 个答案:

答案 0 :(得分:2)

如果数组存储在$scope.abonnements下的范围内,您可以使用ng-repeat

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

见这里:http://jsfiddle.net/89b98cpd/

答案 1 :(得分:0)

假设你的对象有像Abonnements这样的名字

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

然后你就像使用ng-repeat一样

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

例如,使用Abonnement.Abonnement.id访问信息。所以,如果你想要这个文章,它将是Abonnement.Abonnement.vers