【发布时间】:2014-10-14 03:45:56
【问题描述】:
我在一个数据数组上使用 ng-repeat,其中每个值的“类型”都是“图表”或“表格”。在重复时,这些值是有序的,以便图表出现在表格之前。我正在为每个项目是什么类型添加一个类,并且需要添加一个类来指示以下项目是什么,例如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>
【问题讨论】:
-
不能在控制器里面排序吗?
-
尝试:图表数据中的objItem | orderBy:'type' 跟踪 $index
标签: angularjs angularjs-ng-repeat angularjs-orderby