Maybe I'm not doing it right but I'm trying to sort an array of Ember.Object
's by ID in descending order but they are coming out in ascending order still.
saidMessages: [],
Then I have the computed
sortedSaidMessages: Ember.computed.sort('saidMessages','id:desc'),
When I call a method from say a component it adds a new object into the main array
say: function(params) {
if (ENV.environment === 'development' || ENV.environment === 'staging'){
var thisMessage = Ember.Object.create(params);
this._IDify(thisMessage,this.get('saidMessages'));
this.get('saidMessages').pushObject(thisMessage);
setTimeout(()=>{
this._removeMessage(thisMessage,this.get('saidMessages'));
},6000)
}
},
In my template I display them like so
{{#each devlog.sortedSaidMessages as |message|}}
{{devlog-message content=message}}
{{/each}}
But when I add items to the array, no matter if I add a few at the same time, or stagger them (say in a setTimeout function) they are still showing in ascending order (0,1,2,...)
Check out the documentation for Ember.computed.sort: the second argument is the key to a property describing how to sort. Here's what you want instead:
saidMessages: [],
saidMessagesSorting: ['id:desc'],
sortedSaidMessages: Ember.computed.sort('saidMessages','saidMessagesSorting'),