Created
September 18, 2012 18:38
-
-
Save eimermusic/3744939 to your computer and use it in GitHub Desktop.
Tiny simple sort-action for Ember.js ArrayController content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.UsersController = Ember.ArrayController.extend({ | |
sortProperties: ['name'], | |
sortAscending: true, | |
reSort: function(sortBtnValue) { | |
var sortProperty = this.get('sortProperties')[0]; | |
if (sortProperty == sortBtnValue) { | |
if (this.get('sortAscending')) { | |
this.set('sortAscending', false); | |
} else { | |
this.set('sortAscending', true); | |
} | |
} | |
this.set('sortProperties', [sortBtnValue]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can use 'toggleProperty' as well:
App.UsersController = Ember.ArrayController.extend({
sortProperties: ['name'],
sortAscending: true,
reSort: function(sortBtnValue) {
var sortProperty = this.get('sortProperties')[0];
if (sortProperty == sortBtnValue) {
this.toggleProperty('sortAscending');
}
this.set('sortProperties', [sortBtnValue]);
}
});