2016-06-17 71 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

相关问题