角JS NG重复重复的项目
问题描述:
我没有什么问题,我ng-repeat
角JS NG重复重复的项目
$http.get("/test-server/rest/servizi/listaRuoli")
.success(function(data){
\t $scope.servizio = data;
\t console.log(data.label);
})
<div class ="input_form_right">
<strong>Seleziona un Servizio</strong> (obbligatorio)<br>
<select class="size_input_newbg">
<option ng-repeat="x in servizio" ng-bind = "x.label"></option>
</select>
</div>
的问题是,当我在读我不能$index
使用,因为mongodb
轨道网页。 有些想法? 谢谢!
答
使用ng-options
代替:
<select class="size_input_newbg" ng-model="yourmodel"
ng-options="r.id as r.label for r in servizio"
ng-bind = "r.label">
<option value="" disabled="">Select One</option>
</select>
答
试试这个:
<style>
.title-case {
text-transform: capitalize;
}
</style>
<div class ="input_form_right">
<strong>Seleziona un Servizio</strong> (obbligatorio)<br>
<select class="size_input_newbg">
<option class="title-case" ng-repeat="x in servizio track by $index">{{x.label}}</option>
</select>
</div>
的MongoDB无关由$指数做跟踪。如果您尝试删除所有重复选项,我建议将您的GET调用更改为:
$http.get("/test-server/rest/servizi/listaRuoli")
.success(function(data){
var seenBefore = [];
var out = [];
for (var i=0;i<=data.length-1;i++){
if (seenBefore.indexOf(data[i].label) == -1) {
seenBefore.push(data[i].label);
data[i].label = data[i].label.toLowerCase();
out.push(data[i]);
}
}
$scope.servizio = out;
console.log(data.label);
})
您的问题有点混淆。标题说了些什么,问题的内容说了别的。这是什么? – Ionut
你甚至尝试过使用'track by $ index'吗? – Weedoze