"重复在一个中继器不允许"在NG-重复 [英] "Duplicates in a repeater are not allowed" on ng-repeat
本文介绍了"重复在一个中继器不允许"在NG-重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我接到了一个服务请求返回以下JSON数据:
I've got the following json data returned from a service request:
{
"entries": [{
"id": 2081,
"name": "BM",
"niceName": "bodmas"
}]
}, {
"id": 8029,
"name": "Mas",
"niceName": "Masm"
}]
}],
"count": 2
}
和我通过这个数据试图HTML以下code循环:
And I am trying the following code in html to loop through this data:
<option ng-repeat="entry in entries" value="{{entry.name}}">{{entry.name}}</option>
我收到以下错误,当我运行code:
I get the following error when I run the code:
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: entry in entries, Duplicate key: string:c
以下是code为我的控制器:
Following is the code for my controller:
myApp.controller("MyController", ['$scope', '$http', '$log', function($scope, $http, $log){
...
$http.get('https://myServiceURL').success(function(data){
$scope.entries = data;
});
}]);
有人能帮助我理解为什么我收到这个错误?
Could somebody help me understand why am I getting that error?
推荐答案
您JSON是无效的,应该是:
Your JSON is invalid and should be :
{
"entries": [{
"id": 2081,
"name": "BM",
"niceName": "bodmas"
}, {
"id": 8029,
"name": "Mas",
"niceName": "Masm"
}],
"count": 2
}
此外,请确保您在合适的级别访问该文件,使用:
Also, make sure you are accessing the document at the right level, use :
$http.get('https://myServiceURL').success(function(data){
$scope.entries = data.entries;
});
然后,它应该工作。看到这个 JSBin 。
这篇关于&QUOT;重复在一个中继器不允许&QUOT;在NG-重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文