2016-06-17 116 views
0

我有這樣的對象數組的數組,我從結果中傳遞出來的對象數組;爲什麼我的ng-repeat只顯示第一個結果?

[ 
    [ 
{ 
    "id": 4, 
    "name": "THROTTLE TUBE", 
    "partno": "104-", 
    "oemnumber": "46019 038", 
    "stock": 19, 
    "price": "28" 
}, 
{ 
    "id": 28, 
    "name": "TACHOMETER, CUP", 
    "partno": "128-", 
    "oemnumber": "25012 011", 
    "stock": 7, 
    "price": "46" 
} 
    ] 
] 

我從下面得到這個;

$scope.woParts = []; 

//later in my modal code - which is where the double [] is coming from 
modalInstance.result.then(function(woParts) { 
     $scope.woParts.push(woParts); 

我然後在我的視圖中使用這個ng-repeat;

<div ng-repeat="woPart in woParts"> 
    <div class="col-md-4"> 
     @{{ woPart[$index].name }} 
    </div> 
    <div class="col-md-2"> 
     @{{ woPart[$index].oemnumber }} 
    </div> 
    <div class="col-md-2"> 
     @{{ woPart[$index].price | currency}} 
    </div> 
    <div class="col-md-2"> 
     <input type="number" 
      class="form-control" 
      ng-model="partQty"> 
    </div> 
</div> 

這隻顯示數組中的第一個結果。這是爲什麼? 謝謝!

+0

我可以問你爲什麼把雙[]在JSON,如果有一個我認爲它工作正常 – abdoutelb

+0

好問題。檢查我的編輯... – RushVan

+0

嘗試使用{{woPart.name}} 「woPart」,我明白指數組中的對象不使用索引 – abdoutelb

回答

1

我不認爲你應該將woParts推入另一個對象。只需將它保存到範圍:$scope.woParts = woParts;。那麼在ngRepeat中不需要使用$index,只需使用常規點符號:woPart.name

或者,如果您必須將woParts推入另一個陣列,則可以將ngRepeat表達式更改爲woPart in woParts[0]

+0

謝謝你的工作! – RushVan

相關問題