orderBy two fields (one in reverse)

后端 未结 3 1169
野趣味
野趣味 2021-02-03 17:36

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

  • Online firsts / Reversed alphabetic
3条回答
  •  日久生厌
    2021-02-03 18:17

    Change the orderBy filter to this:

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

    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.

提交回复
热议问题