我的ng-repeat
$http.get("/test-server/rest/servizi/listaRuoli")
.success(function(data){
$scope.servizio = data;
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
使用跟踪。
一些想法?
谢谢!
答案 0 :(得分:2)
改为使用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>
答案 1 :(得分:0)
试试这个:
<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与$ index的跟踪无关。如果您尝试删除所有重复选项,我建议您将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);
})