1

I have an array of objects that have a "Category" property. In my ng-repeat, I am creating a group by conditionally showing a header row with the category name if it is different that the previous value by using items[$index - 1] to check the previous value. This works, but if I apply an orderBy filter, it would seem that $index doesn't reflect the new order. What am I doing wrong?

4

1 回答 1

5

我一发布这个,我就意识到什么可以解决它。我补充说track by item.itemId,它开始按预期运行。

<div class="row" ng-repeat="item in items track by item.itemId | filter: searchTerms | orderBy:['Category1', 'Category2']">
  <div class="rowHeader" ng-show="$index == 0 || item.Category1 != items[$index -1].Category1">
    {{item.Category1}}
  </div>
</div>
于 2014-05-14T21:18:32.253 回答