Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys
有没有人能帮我解决这个错误,我不知道这个问题是怎么回事,我只想显示从数据库服务器到 html 的 json 数组使用 angular syntax (ng-repeat) 但我得到一个错误说 Error: [ngRepeat:dupes] Repeater 中不允许重复。使用 'track by' 表达式指定唯一键。转发器:datatemans 中的 datateman,重复键:字符串:”,重复值:“
这是代码..
<div class="bar bar-header">
<button class="button button-icon icon ion-navicon"></button>
<div class="h1 title">Data Teman</div>
<button class="button button-clear button-positive">LogOut</button>
</div>
<ion-view>
<ion-content padding="false" class="has-header">
<ion-refresher
pulling-text="Pull to refresh..."
on-refresh="showData()">
</ion-refresher>
<ion-list show-Delete = "data.showDelete" show-Reorder = "data.showReorder">
<ion-item class="item-avatar item-icon-right" ng-repeat="datateman in datatemans" type="item-text-wrap" href="#/tab/teman/{{datateman.id}}">
<img ng-src="{{datateman.icon}}">
<i class="icon ion-ios7-arrow-right"></i>
<h2>{{datateman.username}}
<br>
<font size="2" color="gray" >Spesialis : {{datateman.password}}</font>
</h2>
<ion-delete-button class="ion-minus-circled" ng-click="delete(datateman);"></ion-delete-button>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
这是我获得 json 数组的代码..
.factory('temanService', function($http) {
var baseUrl = 'http://dwellingtime.net23.net/DwellingTime/';
return {
getAll: function() {
return $http.get(baseUrl+'select.php');
},
getId: function (temanId){
return $http.get(baseUrl+'select_id.php?id='+temanId);
},
create: function (datateman){
return $http.post(baseUrl+'insert.php',datateman,{
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;'
}
});
},
update: function (datateman){
return $http.post(baseUrl+'update.php',datateman,{
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;'
}
});
},
delete: function (id){
return $http.get(baseUrl+'delete.php?id='+id);
}
};
});
描述了实际问题here
AngularJS 不允许在 ng-repeat
指令中重复。这意味着如果您尝试执行以下操作,您将收到错误消息。
<div ng-repeat="item in [a,a,a]">
不过,稍微改变一下上面的代码,定义一个索引来判断唯一性,
<div ng-repeat="item in [a,a,a] track by $index">
将您的 ng-repeat="datateman in datatemans"
替换为 ng-repeat="datateman in datatemans track by $index"
html
<div class="bar bar-header">
<button class="button button-icon icon ion-navicon"></button>
<div class="h1 title">Data Teman</div>
<button class="button button-clear button-positive">LogOut</button>
</div>
<ion-view>
<ion-content padding="false" class="has-header">
<ion-refresher pulling-text="Pull to refresh..." on-refresh="showData()">
</ion-refresher>
<ion-list show-Delete="data.showDelete" show-Reorder="data.showReorder">
<ion-item class="item-avatar item-icon-right" ng-repeat="datateman in datatemans track by $index" type="item-text-wrap" href="#/tab/teman/{{datateman.id}}">
<img ng-src="{{datateman.icon}}">
<i class="icon ion-ios7-arrow-right"></i>
<h2>{{datateman.username}}
<br>
<font size="2" color="gray" >Spesialis : {datateman.password}}</font>
</h2>
<ion-delete-button class="ion-minus-circled" ng-click="delete(datateman);"></ion-delete-button>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
有没有人能帮我解决这个错误,我不知道这个问题是怎么回事,我只想显示从数据库服务器到 html 的 json 数组使用 angular syntax (ng-repeat) 但我得到一个错误说 Error: [ngRepeat:dupes] Repeater 中不允许重复。使用 'track by' 表达式指定唯一键。转发器:datatemans 中的 datateman,重复键:字符串:”,重复值:“
这是代码..
<div class="bar bar-header">
<button class="button button-icon icon ion-navicon"></button>
<div class="h1 title">Data Teman</div>
<button class="button button-clear button-positive">LogOut</button>
</div>
<ion-view>
<ion-content padding="false" class="has-header">
<ion-refresher
pulling-text="Pull to refresh..."
on-refresh="showData()">
</ion-refresher>
<ion-list show-Delete = "data.showDelete" show-Reorder = "data.showReorder">
<ion-item class="item-avatar item-icon-right" ng-repeat="datateman in datatemans" type="item-text-wrap" href="#/tab/teman/{{datateman.id}}">
<img ng-src="{{datateman.icon}}">
<i class="icon ion-ios7-arrow-right"></i>
<h2>{{datateman.username}}
<br>
<font size="2" color="gray" >Spesialis : {{datateman.password}}</font>
</h2>
<ion-delete-button class="ion-minus-circled" ng-click="delete(datateman);"></ion-delete-button>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
这是我获得 json 数组的代码..
.factory('temanService', function($http) {
var baseUrl = 'http://dwellingtime.net23.net/DwellingTime/';
return {
getAll: function() {
return $http.get(baseUrl+'select.php');
},
getId: function (temanId){
return $http.get(baseUrl+'select_id.php?id='+temanId);
},
create: function (datateman){
return $http.post(baseUrl+'insert.php',datateman,{
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;'
}
});
},
update: function (datateman){
return $http.post(baseUrl+'update.php',datateman,{
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;'
}
});
},
delete: function (id){
return $http.get(baseUrl+'delete.php?id='+id);
}
};
});
描述了实际问题here
AngularJS 不允许在 ng-repeat
指令中重复。这意味着如果您尝试执行以下操作,您将收到错误消息。
<div ng-repeat="item in [a,a,a]">
不过,稍微改变一下上面的代码,定义一个索引来判断唯一性,
<div ng-repeat="item in [a,a,a] track by $index">
将您的 ng-repeat="datateman in datatemans"
替换为 ng-repeat="datateman in datatemans track by $index"
html
<div class="bar bar-header">
<button class="button button-icon icon ion-navicon"></button>
<div class="h1 title">Data Teman</div>
<button class="button button-clear button-positive">LogOut</button>
</div>
<ion-view>
<ion-content padding="false" class="has-header">
<ion-refresher pulling-text="Pull to refresh..." on-refresh="showData()">
</ion-refresher>
<ion-list show-Delete="data.showDelete" show-Reorder="data.showReorder">
<ion-item class="item-avatar item-icon-right" ng-repeat="datateman in datatemans track by $index" type="item-text-wrap" href="#/tab/teman/{{datateman.id}}">
<img ng-src="{{datateman.icon}}">
<i class="icon ion-ios7-arrow-right"></i>
<h2>{{datateman.username}}
<br>
<font size="2" color="gray" >Spesialis : {datateman.password}}</font>
</h2>
<ion-delete-button class="ion-minus-circled" ng-click="delete(datateman);"></ion-delete-button>
</ion-item>
</ion-list>
</ion-content>
</ion-view>