简体   繁体   中英

Multiple sorting with ascending and descending in Parse Cloud

I have the following Result Class in Parse:

score <Number>  |  miliseconds <Number>
50              |  500
100             |  10000
100             |  20000
50              |  1000
50              |  2000
100             |  99999

I'm trying to sort descending by score first and then ascending by miliseconds

First try:

var query = new Parse.Query('Result')
query.descending('score')
query.ascending('time')
return query.find()

And I get this:

score <Number>  |  miliseconds <Number>
50              |  500
50              |  1000
50              |  2000
100             |  10000
100             |  20000
100             |  99999

Second try:

var query = new Parse.Query('Result')
query.ascending('time')
query.descending('score')
return query.find()

Result:

score <Number>  |  miliseconds <Number>
100             |  99999
100             |  10000
100             |  20000
50              |  500
50              |  1000
50              |  2000

What am I expecting?

I'm expecting to have a result like this:

score <Number>  |  miliseconds <Number>
100             |  10000
100             |  20000
100             |  99999
50              |  500
50              |  1000
50              |  2000

Am I doing something wrong here?

Try this way:

var query = new Parse.Query('Result')
query.descending('score')
query.addAscending('time')
return query.find()

The thing is to add another sorting condition, not overriding pervious one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM