如何在这种数据格式上使用ng-repeat

时间:2015-09-09 04:39:05

标签: angularjs angularjs-ng-repeat ng-repeat

如何对这种数据格式使用ng-repeat?

控制器:

$scope.makes = [
        {
       "makes": [
          {
             "id": 200347864,
             "name": "AM General",
             "niceName": "am-general"
          },
{
             "id": 200347800,
             "name": "Toyota",
             "niceName": "toyota"
          }
            ]
        }

      ];

HTML:

<body ng-controller="MakeListCtrl">
  <ul>
    <li ng-repeat="make in makes">


      <p >name: {{make.name}}</p>
    </li>
  </ul>

</body>

4 个答案:

答案 0 :(得分:1)

<body ng-controller="MakeListCtrl">
  <ul>
    <li ng-repeat="maker in makes"> 
      <ul>
        <li ng-repeat="make in maker.makes"> 
         <p >name: {{make.name}}</p>
        </li>
      </ul>
    </li>
  </ul>
</body>

答案 1 :(得分:0)

你可以简单地使数组对象。无需更改html只需更改js

HTML

<body ng-controller="MakeListCtrl">
  <ul>
    <li ng-repeat="make in makes">    
      <p >name: {{make.name}}</p>
    </li>
  </ul>
</body>

控制器

$scope.makes = [
    {
        "id": 200347864,
        "name": "AM General",
        "niceName": "am-general"
    },
    {
        "id": 200347864,
        "name": "AM General",
        "niceName": "am-general"
    },
    {
        "id": 200347864,
        "name": "AM General",
        "niceName": "am-general"
    }];

答案 2 :(得分:0)

 <body ng-controller="MakeListCtrl">
   <ul>
     <li ng-repeat="make in makes[0].makes">


       <p >name: {{make.name}}</p>
     </li>
   </ul>

</body> 

答案 3 :(得分:0)

<body ng-controller="MakeListCtrl">
  <ul ng-repeat="maker in makes">
        <li ng-repeat="make in maker.makes"> 
         <p >name: {{make.name}}</p>
        </li>
  </ul>
</body>

 Above will be a better way please try this.