I noticed this on the EmberJS website under Filtering:
Another common task to perform on an Enumerable is to take the
Enumerable as input, and return an Array after sorting or filtering it
based on some criteria.
Imagine I have an array of Ember objects, how do I go about sorting them by property?
App.DemoArray = Ember.ArrayController.create({
content:[
Ember.Object.create({name:'Joe', Age:29}),
Ember.Object.create({name:'Jim', Age:53}),
Ember.Object.create({name:'Jack', Age:12})
]
})
What if I wanted to sort the above by age? Thanks for your help!
EDIT:
I found this in the sproutcore documentation but it doesn't seem to work with Ember:
You can sort an Enumerable based on the value of some property or list
of properties using sortProperty. If you pass in multiple properties,
SproutCore will sort items with the same value for the first property
by the value of the second parameter, and so on.
Section 3.8 on this page: http://guides.sproutcore20.com/enumerables.html
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…