我遇到AngularJS中继器的问题:
<table class="data_table" style="margin: 0 5px; width: calc(100% - 10px);">
<tr>
<th>Activity</th>
<th ng-repeat="date in activitiesRangeInfo.labels">{{date | date: 'd/MM'}}</th>
</tr>
<tr ng-repeat="activity in activitiesRangeInfo.generated_datasets track by $index">
<th>{{activitiesRangeInfo.all_activities[$index]}}</th>
<td align="center" ng-repeat="inner in activitiesRangeInfo.generated_datasets[$index] track by $index">
{{inner | number: 1}}
</td>
</tr>
</table>
和这个数据集:
$scope.activitiesRangeInfo = {
all_activities: ["Tennis"],
generated_datasets: [[0, 0, 420, 0]],
labels: JSON.parse('["2016-10-22T13:00:00.000Z","2016-10-23T13:00:00.000Z","2016-10-24T13:00:00.000Z","2016-10-25T13:00:00.000Z"]')
}
并出现此错误:
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: inner in activity track by $indexb, Duplicate key: undefined, Duplicate value: 0
请查看并告知错误。
答案 0 :(得分:1)
$indexb
无效,因为它是Angular定义的属性。只需使用$index
即可。如果您想定义自己的内容,请参阅:https://docs.angularjs.org/api/ng/directive/ngInit