排序依据两个字段(一个反向) [英] orderBy two fields (one in reverse)
问题描述
我想订购按状态的朋友列表(联机首创,离线持续)和字母顺序排列。所有我设法得到的是:
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 暴露我的问题
推荐答案
更改排序依据
过滤这样:
orderBy:['-status','name']
,然后上升的名字 -
这将递减状态(字符由prefixing的)命令。目前,你传递
真正
来反向排序,这是造成状态是正确的(在线第一),但名字被逆转(即递减)。
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).
如果你想保持反向布尔值,你可以使用排序依据:['地位',' - 名']:真正的
但这似乎不是仅仅做不太清楚状态
降如上文所示。
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.
这篇关于排序依据两个字段(一个反向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!