orderBy 两个字段(一个反向) [英] orderBy two fields (one in reverse)

查看:42
本文介绍了orderBy 两个字段(一个反向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按状态(在线第一个,离线最后一个)和字母顺序对朋友列表进行排序.我设法得到的是:

I would like to order a friend list by status (online firsts, offline lasts) and by alphabetical order. All I manage to get is:

  • 在线第一次/颠倒字母顺序
  • 或离线优先/字母顺序

这是 plunker 来揭露我的问题

Here is plunker to expose my problem

推荐答案

orderBy 过滤器更改为:

orderBy:['-status','name']

这将按状态降序(通过前缀 - 字符),然后升序名称.目前您正在传递 true 以反转排序,这导致状态正确(在线优先),但名称要反转(即降序).

This will order by descending status (by prefixing the - character), then ascending name. Currently you're passing true to reverse the sort, which is causing the status to be correct (online first), but the names to be reversed (i.e., descending).

如果你想保留反向布尔值,你可以使用 orderBy:['status','-name']:true 但这似乎比仅仅制作 status 降序,如前所示.

If you want to keep the reverse boolean, you could use orderBy:['status','-name']:true but that seems less clear than just making status descending as shown earlier.

这篇关于orderBy 两个字段(一个反向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆