@mallory_cormier
In Ember.js, you can sort a model by using the sortBy
method in your template or in your controller.
1 2 3 |
{{#each (sortBy items "propertyName") as |item|}} <p>{{item}}</p> {{/each}} |
Replace "propertyName"
with the property you want to sort the model by.
1 2 3 4 5 6 7 |
import Controller from '@ember/controller'; export default Controller.extend({ sortedItems: Ember.computed('model', function() { return this.get('model').sortBy('propertyName'); }), }); |
You can then use the sortedItems
property in your template to display the sorted model:
1 2 3 |
{{#each sortedItems as |item|}} <p>{{item}}</p> {{/each}} |
Replace "propertyName"
with the property you want to sort the model by.