【发布时间】:2015-11-21 17:06:05
【问题描述】:
我想遍历一个列表,例如:
$scope.articles = [
{ id: 1, name: "Pizza Vegetaria", price: 5 },
{ id: 2, name: "Pizza Salami", price: 5.5 },
{ id: 3, name: "Pizza Thunfisch", price: 6 }
];
如果我用另一个 ng-repeat 再次遍历这个列表,我希望 $index 继续,而不是从头开始。那么是否可以将索引从一个 ng-repeat 范围传递到另一个范围? 所以不要得到这个结果:
0 Pizza Vegetaria 5
1 Pizza Salami 5.5
2 Pizza Thunfisch 6
0 Pizza Vegetaria 5
1 Pizza Salami 5.5
2 Pizza Thunfisch 6
我想要这个结果:
0 Pizza Vegetaria 5
1 Pizza Salami 5.5
2 Pizza Thunfisch 6
3 Pizza Vegetaria 5
4 Pizza Salami 5.5
5 Pizza Thunfisch 6
HTML 如下所示:
<table class="table">
<tr ng-repeat="article in articles track by $index">
<td>{{$index}}</td>
<td>{{article.name}}</td>
<td>{{article.price}}</td>
</tr>
</table>
<table class="table">
<tr ng-repeat="article in articles track by $index">
<td>{{$index}}</td>
<td>{{article.name}}</td>
<td>{{article.price}}</td>
</tr>
</table>
提前致谢!
【问题讨论】:
标签: arrays angularjs scope angularjs-scope angularjs-ng-repeat