获得ng-repeat上的排序索引

时间:2014-10-13 15:54:26

标签: angularjs angularjs-ng-repeat angularjs-orderby

我在数据数组上使用ng-repeat,其中每个值都具有'chart'或'table'的'type'。在重复时,将对值进行排序,以便在表格之前显示图表。我正在为每个项目的类型添加一个类,并且需要添加一个类来指示以下项目是什么,例如class="chart next-chart"class="chart next-table"

问题是索引反映了未排序的数据。如何提取有关排序列表中下一项的信息?

以下是目前的代码:

<div class="{{objItem.type}}" ng-class="'next-' + chartData[$index + 1].type" ng-repeat="objItem in chartData | orderBy:'type'">{{objItem.name}}</div>

1 个答案:

答案 0 :(得分:0)

感谢deonclem指向解决方案:

<div class="{{objItem.type}}" ng-class="'next-' + filteredItems[$index + 1].type" ng-repeat="objItem in (filteredItems = (chartData | orderBy:'type'))">{{objItem.name}}</div>
相关问题