This question already has answers here:
Error: [ngRepeat:dupes] what does this mean?
(2个答案)
5个月前关闭。
如何在javascript数组中输入连续的null?
我无法理解如何在JS数组中输入连续的空值。这是我的工作脚本:
(2个答案)
5个月前关闭。
如何在javascript数组中输入连续的null?
我无法理解如何在JS数组中输入连续的空值。这是我的工作脚本:
var myApp = angular.module("myApp", []);
myApp.controller("myCtrl", function($scope) {
$scope.items = [];
$scope.items[0] = [,,"this doesn't work"];
$scope.items[0] = [null,"this works"];
$scope.items[1] = [null,,"this works"];
$scope.items[2] = [null,null,"this doesn't work"];
$scope.items[3] = [null,,,"this doesn't work"];
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<table>
<tr ng-repeat="row in items">
<td ng-repeat="column in row">{{column}}</td>
</tr>
</table>
</div>
</body>
最佳答案
问题在于您如何在角度ng-repeat中使用值。更改代码以使用track by处理重复的值。
<tr ng-repeat="tr in items">
<td ng-repeat="td in tr track by $index">{{td}}</td>
</tr>
关于javascript - ngRepeat:dupes在数组中输入null时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59274539/
10-10 22:23