AngularJS orderBy不与groupBy合作

AngularJS orderBy不与groupBy合作,angularjs,Angularjs,我有一个ng中继器,看起来像这样: <ul> <li ng-repeat="item in controller.collections.data | orderBy: '-plannedCollectionDate'"> {{ item.plannedCollectionDate | date: 'fullDate' }} </li> </ul> 这很好,它获取数据并反向排序,但是当我尝试使用groupBy过滤器

我有一个ng中继器,看起来像这样:

<ul>
    <li ng-repeat="item in controller.collections.data | orderBy: '-plannedCollectionDate'">
        {{ item.plannedCollectionDate | date: 'fullDate' }}
    </li>
</ul>
这很好,它获取数据并反向排序,但是当我尝试使用groupBy过滤器时,orderBy被忽略。 起初我是这样试的:

<div ng-repeat="(key, value) in controller.collections.data | groupBy: 'plannedCollectionDate' | orderBy: '-plannedCollectionDate'">

    {{ key | date: 'fullDate' }}

    <table class="table table-hover table-light">
        <tbody>
            <tr ng-repeat="collection in value | filter: controller.filter" ng-click="controller.select(collection)" ng-class="{ active: controller.isSelected(collection), warning: collection.status.id === 2, success: collection.status.id === 4, danger: collection.status.id === 5 }">
                <td>
                    <div>{{ collection.supplierName }} {{ collection.description }}</div>
                    <div>to be collected by {{ collection.customerName }}</div>
                </td>
                <td>
                    <a ui-sref=".collect({ selected: [collection]})">{{ collection.status.name }}</a>
                </td>
                <td>
                    <button class="btn btn-danger" ng-click="controller.delete(collection.id)">
                        <span class="fa fa-close"></span>
                    </button>
                </td>
            </tr>
        </tbody>
    </table>
</div>
但它不起作用。在使用谷歌后,我发现了一个解决方案,建议如下:

<div ng-repeat="group in controller.collections.data | groupBy: 'plannedCollectionDate' | toArray: true | orderBy: '-plannedCollectionDate'">

    {{ group.$key | date: 'fullDate' }}

    <table class="table table-hover table-light">
        <tbody>
            <tr ng-repeat="collection in group | filter: controller.filter" ng-click="controller.select(collection)" ng-class="{ active: controller.isSelected(collection), warning: collection.status.id === 2, success: collection.status.id === 4, danger: collection.status.id === 5 }">
                <td>
                    <div>{{ collection.supplierName }} {{ collection.description }}</div>
                    <div>to be collected by {{ collection.customerName }}</div>
                </td>
                <td>
                    <a ui-sref=".collect({ selected: [collection]})">{{ collection.status.name }}</a>
                </td>
                <td>
                    <button class="btn btn-danger" ng-click="controller.delete(collection.id)">
                        <span class="fa fa-close"></span>
                    </button>
                </td>
            </tr>
        </tbody>
    </table>
</div>
但这也不行。 有人能帮我解决这个问题吗?

angular filter的用户组已经编写了需要执行的操作

示例:groupBy返回一个对象,但orderBy fiter需要一个数组。因此,请使用toArray:true并为orderBy提供一个要使用的数组:

控制器:

$scope.objectToArray= function(arr) {  
    return $filter('objectToArray')
      ($filter('map')(arr, 'id'));
      }
视图: 现在OrderBy可以在ng repeat中使用$scope.objectToArray:

德国劳埃德船级社

<div ng-repeat="group in controller.collections.data | groupBy: 'plannedCollectionDate' | toArray: true | orderBy: '-objectToArray'">