Last active
August 1, 2016 01:59
-
-
Save ksol/cf199f1f76ad8221a065 to your computer and use it in GitHub Desktop.
Ember.js: sorting with computed properties
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
export default Ember.Controller.extend({ | |
posts: [], // Filled by real world data by the route | |
postsSorting: ['name'], | |
postsSortingDesc: ['name:desc'], | |
sortedPosts: Ember.computed.sort('posts', 'postsSorting'), | |
sortedPostsDesc: Ember.computed.sort('posts', 'postsSortingDesc'), | |
customSortedPost: Ember.computed.sort('posts', function(a, b) { | |
// return a negative when a < b, 0 when a = b, and a positive when a > b | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment