SortBy descending to Ember

I sort the collection, which is a computed property in my model:

collection: function() { var entries = this.get('entries'); return entries.sortBy('prop1', 'prop2'); }.property('entries.@each.prop1', 'entries.@each.prop2') 

But I can’t figure out how to sort it in descending order. It should be easy, right?

Ember 1.13

+8
source share
1 answer

You can use the Ember.computed.sort macro: http://emberjs.com/api/classes/Ember.computed.html#method_sort

Example:

 entriesSorting: ['prop1:desc', 'prop2:desc'], collection: Ember.computed.sort('entries', 'entriesSorting') 

Unrelated but relevant: It is recommended that you use Ember.computed over the extension of the .property prototype.

UPDATE: The following is an example of this work: https://ember-twiddle.com/19ff8c56f1c13512bdc8

+16
source share

All Articles