Skip to content

Instantly share code, notes, and snippets.

@grapho
Last active January 21, 2016 19:12
Show Gist options
  • Save grapho/05732a0763d7c9768598 to your computer and use it in GitHub Desktop.
Save grapho/05732a0763d7c9768598 to your computer and use it in GitHub Desktop.
Move Items Up and Down
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
init() {
this._super(...arguments);
this.processes = [
{name: "1"},
{name: "2"},
{name: "3"},
{name: "4"}
];
},
actions: {
moveProcessUp(process) {
let processes = this.get('processes'),
newIndex = processes.indexOf(process) - 1;
processes.removeObject(process);
processes.insertAt(newIndex, process);
},
moveProcessDown(process) {
let processes = this.get('processes'),
newIndex = processes.indexOf(process) + 1;
processes.removeObject(process);
processes.insertAt(newIndex, process);
}
}
});
<h1>Welcome to {{appName}}</h1>
<ul>
{{#each processes as |process|}}
<li>
<button {{action "moveProcessUp" process}}>&#8593;</button>
{{process.name}}
<button {{action "moveProcessDown" process}}>&#8595;</button>
</li>
{{/each}}
</ul>
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment