2016-11-07 185 views
3

我沒有什麼問題,我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軌道網頁。 有些想法? 謝謝!

+1

您的問題有點混淆。標題說了些什麼,問題的內容說了別的。這是什麼? – Ionut

+0

你甚至嘗試過使用'track by $ index'嗎? – Weedoze

回答

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> 
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無關由$指數做跟蹤。如果您嘗試刪除所有重複選項,我建議將您的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); 
})