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>
這隻顯示數組中的第一個結果。這是爲什麼? 謝謝!
我可以問你爲什麼把雙[]在JSON,如果有一個我認爲它工作正常 – abdoutelb
好問題。檢查我的編輯... – RushVan
嘗試使用{{woPart.name}} 「woPart」,我明白指數組中的對象不使用索引 – abdoutelb