Created
December 27, 2013 04:36
-
-
Save mockra/8142638 to your computer and use it in GitHub Desktop.
This file contains 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
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