当我以JSON格式获取数据并尝试使用ng-repeat
标记打印时,我收到错误
ng-dupes error
<table>
<tr ng-repeat="emp in empArr">
<td>{{emp.empcode}}</td>
<td>{{emp.empName}}</td>
</tr>
</table>
还检索json格式的AngularJS函数:
$scope.Show = function() {
$http.get("get_oracle_data.jsp?sqlStr=SELECT empcode,empname from emp")
.then(function(response) {
$scope.empArr = response.data;
});
有谁能告诉我这有什么问题?
答案 0 :(得分:2)
使用trackBy
来避免重复错误。
<table>
<tr ng-repeat="emp in empArr track by $index">
<td>{{emp.empcode}}</td>
<td>{{emp.empName}}</td>
</tr>
</table>
答案 1 :(得分:0)
你可以试试这个:
跟踪$ index 用于从数组列表中删除重复项:
<table>
<tr ng-repeat="emp in empArr track by $index">
<td>{{emp.empcode}}</td>
<td>{{emp.empName}}</td>
</tr>
</table>
答案 2 :(得分:-1)
你可以查看这个小提琴中的类似例子
<div ng-app='t' ng-controller='test'>
<div ng-repeat='x in DATA'>
<p>
<label>Title: </label> {{x.complaint_title}}
</p>
</div>
</div>
(function(){
var app = angular.module('t', []);
app.controller('test',
[
'$scope',
function($scope)
{
$scope.DATA = [
{
"complaint_id": "1",
"complaint_title": "blah",
"complaint_desc": "gdga",
"incident_date": "2015-02-28"
},
{
"complaint_id": "2",
"complaint_title": "gbsdsg",
"complaint_desc": "asadf",
"incident_date": "2015-02-27"
}
];
}
]);//controller
})();//closure