【问题标题】:Angular: Sort by list of properties with mixed ASC and DESCAngular:按具有混合 ASC 和 DESC 的属性列表排序
【发布时间】:2014-01-31 05:29:58
【问题描述】:

我有一个 ng-repeat,我正在尝试获取特定订单。我发现我可以使用属性列表进行订购:

ng-repeat="client in clients | orderBy: ['isOpen', 'lastAccessTime']"

我的问题是,如何配置升序和降序?

我想要使用 DESC 对 isOpen 进行主要排序,并使用 ASC 对 lastAccessTime 进行二次排序。如何在我的ng-repeat 中实现这一点?

编辑:我在下面尝试过,但是当两个项目都是isOpen 时,最高的lastAccessTime 不在顶部:

ng-repeat="client in clients | orderBy: 'isOpen':true | orderBy: 'lastAccessTime'"

【问题讨论】:

    标签: javascript angularjs sorting


    【解决方案1】:

    您可以在属性名称前加上+- 以指示升序或降序,如指定的in the documentation for orderBy

    【讨论】:

      【解决方案2】:

      您可以使用一个数组,并且可以选择以 + 或 - 为前缀来控制升序或降序排序

      ng-repeat="client in clients | orderBy: ['isOpen','-lastAccessTime']"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-11
        • 1970-01-01
        • 1970-01-01
        • 2010-12-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多