我有一个如下对象:
scope.items = {
"poor-John-1": {
"_id": "poor-John-1",
"name": "poor-John-1",
"sName": "room-poor-John-2"
},
"poor-John-2": {
"_id": "poor-John-2",
"name": "poor-John-2",
"sName": "room-poor-John-2"
}
}
我已按以下方式渲染对象
<tr ng-repeat="item in items | orderObjectBy: '_id' track by item._id" ng-class="getStyle(item, next_item)"><td>{{item.sName}}</td></tr>
我想要做的是,将current和next_item传递给getStyle函数,因为它不是数组,$ index没有指向值。我有对象数据。
答案 0 :(得分:0)
也许你可以用
来做到这一点$scope.keys = Object.keys($scope.items) // put keys on scope
// get next from keys
<tr ng-repeat="(key, item) in items track by item._id" ng-class="getStyle(item, items[keys[$index +1]])">
<td>{{key}}</td>
<td>{{item.name}}</td>
<td>next : {{items[keys[$index +1]]}}</td>
</tr>
看看这个,告诉我这是不是你想要的https://plnkr.co/edit/GCNmWb9Qv2mntqTnGsX1?p=preview