解决ng-repeat循环数组中有同样的数据挂掉情况

<!DOCTYPE html>
<html lang="en" ng-app="filter">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="js/angular.min.js"></script>
</head>
<body ng-controller="con1">
<ul>
<li ng-repeat="i in arr">{{i|number:'2'|ZH}}</li>
</ul>
<script>
var app = angular.module('filter', []);
app.filter('ZH',function () {
return function (money) {
return '¥'+money;
}
})
app.controller('con1',function ($scope) {
$scope.arr = [5.2,5,7.9,3,5.2];
});
</script>
</body>
</html>
$scope.arr = [5.2,5,7.9,3,5.2];这个数组中有两条同样的数据,如果直接遍历的话就会挂掉。
解决方法:
<li ng-repeat="i in arr track by $index">{{i|number:'2'|ZH}}</li>
原文地址:https://www.cnblogs.com/qiudongjie/p/6640562.html