Angularjs:角度嵌套重复不起作用

时间:2015-05-19 08:41:22

标签: javascript angularjs

关注this article

但它似乎不适用于我的json结构。这是我的json

$scope.trucks = [{
  id: 4,
  truckNumber: '50LD 02456',
  driverName: 'Dẻo',
  shipments: [{
    id: 1,
    routeCode: "THC-VinhHao",
    trip: 2
  }, {
    id: 2,
    routeCode: "THC-VinhHao(R)",
    trip: 3
  }, {
    id: 3,
    routeCode: "THC2-Hiệp Thành HM",
    trip: 3
  }]
}, {
  id: 5,
  truckNumber: '61C 03948',
  driverName: 'Hưng',
  shipments: [{
    id: 4,
    routeCode: "TBC-VBL HMo",
    trip: 1
  }, {
    id: 5,
    routeCode: "THC2-Hiệp Thành HM",
    trip: 4
  }]
}];
<ul>
  <li data-ng-repeat="truck in trucks">
    {{truck.truckNumber}}
    <br />
    <ul>
      <li data-np-repeat="shipment in truck.shipments">{{shipment.routeCode}}</li>
    </ul>
  </li>
</ul>

感谢任何帮助。谢谢你的阅读。

3 个答案:

答案 0 :(得分:1)

请确保您已正确拼写所有内容。 ng-repeat拼写错误。

<ul>
  <li data-ng-repeat="truck in trucks">
    {{truck.truckNumber}}
    <br/>
    <ul>
      <li data-ng-repeat="shipment in truck.shipments">{{shipment.routeCode}}</li>
    </ul>
  </li>
</ul>

答案 1 :(得分:1)

Change np-repeat to ng-repeat then it will work.    
<ul>
      <li data-ng-repeat="truck in trucks track by $index">
          {{truck.truckNumber}}
        <br />
        <ul>
          <li data-ng-repeat="shipment in truck.shipments track by $index">{{shipment.routeCode}}</li>
        </ul>
      </li>
    </ul>

答案 2 :(得分:0)

<ul>
  <li data-ng-repeat="truck in trucks">
    {{truck.truckNumber}}
    <br />
    <ul>
      <li data-np-repeat="shipment in truck.shipments">{{shipment.routeCode}}</li>
    </ul>
  </li>
</ul>

有一个错字。

<li data-ng-repeat="shipment in truck.shipments">{{shipment.routeCode}}</li>