【问题标题】:get sorted index on ng-repeat在 ng-repeat 上获取排序索引
【发布时间】: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>

【问题讨论】:

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


【解决方案1】:

感谢 deonclem 指出解决方案:

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

【讨论】:

    猜你喜欢
    • 2014-09-29
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 2014-04-12
    相关资源
    最近更新 更多