Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.