Skip to content Skip to sidebar Skip to footer

Ember - Computed Sort

I am using the below code for sorting a list. sortOptions: ['amount:desc','place'] Ember.computed.sort('model',sortOptions) The key 'amount' is basically a number, but in JSON 'mo

Solution 1:

you can use custom function with the Ember.computed.sort which can solve your problem

I believe you get string as amount from JSON and you want to sort it as descending order.

// using a custom sort function
Ember.computed.sort('model', function(a, b){
  if (a.amount > b.amount) {
    return -1;
  } else if (a.amount < b.amount) {
    return 1;
  } else {
    return 0;
  }
})

Post a Comment for "Ember - Computed Sort"