Created
May 30, 2016 15:25
-
-
Save christoph-daehne/d94584677619d5465fadc24d2af3dbf3 to your computer and use it in GitHub Desktop.
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
import Ember from 'ember'; | |
/** | |
* use "{{yield sorted}}" as handlebars template | |
*/ | |
export default Ember.Component.extend({ | |
list: undefined, | |
property: undefined, | |
sorted: function () { | |
const list = this.get("list"); | |
if (!list) { | |
return []; | |
} | |
return list.sort((a, b) => { | |
const x = this._getValue(a); | |
const y = this._getValue(b); | |
return (x < y) ? -1 : (x > y) ? 1 : 0; | |
}); | |
}.property("list", "property"), | |
_getValue(x) { | |
const property = this.get("property"); | |
const value = property === null ? x : x[property]; | |
if ((typeof value) === "string") { | |
return value.toLocaleLowerCase(); | |
} else { | |
return value; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment