Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing Sorted Properties
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
sortProperties: ['position'],
sorted: Ember.computed.sort('model', 'sortProperties'),
actions: {
upPosition(m) {
m.set('position', m.get('position') + 1);
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return [
Ember.Object.create({ 'title': "A", 'position': 1 }),
Ember.Object.create({ 'title': "B", 'position': 2 }),
Ember.Object.create({ 'title': "D", 'position': 4 }),
Ember.Object.create({ 'title': "C", 'position': 3 })
];
}
});
<h1>Welcome to {{appName}}</h1>
<br>
{{#each sorted as |m|}}
{{m.title}} - {{m.position}}
<button {{action 'upPosition' m}}>Up</button><br>
{{/each}}
{
"version": "0.4.11",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.0.1/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.0.1/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.0.1/ember-template-compiler.js"
}
}
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.