Skip to content

Instantly share code, notes, and snippets.

@mockra
Created December 27, 2013 04:36
Show Gist options
  • Save mockra/8142638 to your computer and use it in GitHub Desktop.
Save mockra/8142638 to your computer and use it in GitHub Desktop.
App.TodosController = Ember.ArrayController.extend({
actions: {
createTodo: function () {
// Get the todo title set by the "New Todo" text field
var title = this.get('newTitle');
if (!title.trim()) { return; }
// Create the new Todo model
var todo = this.store.createRecord( App.Todo, {
title: title,
isCompleted: false
});
// Clear the "New Todo" text field
this.set('newTitle', '');
// Save the new model
todo.save();
},
clearCompleted: function () {
var completed = this.filterBy('isCompleted', true);
completed.invoke('deleteRecord');
completed.invoke('save');
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment