From 1134b4860f35990cf045097a5642e7886f6eed55 Mon Sep 17 00:00:00 2001 From: Ryan Cook Date: Thu, 19 May 2011 19:03:49 -0600 Subject: [PATCH] update to include fix for clearCompletedTasks in todoListController not functioning after updating Todo to be SC.Record instead of SC.Object --- source/getting_started_2.textile | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/source/getting_started_2.textile b/source/getting_started_2.textile index 6a7a0f9..2922667 100644 --- a/source/getting_started_2.textile +++ b/source/getting_started_2.textile @@ -101,7 +101,7 @@ SC.ready(function() { Now refresh the page and you should see that all of the todos from fixtures are displayed in the view. -The last piece is making sure that the store knows about new records. Update the controller's +createTodo+ method to use SC.Store's +createRecord+ method: +Next, we need to make sure that the store knows about new records. Update the controller's +createTodo+ method to use SC.Store's +createRecord+ method: createTodo: function(title) { @@ -109,7 +109,28 @@ The last piece is making sure that the store knows about new records. Update the }, -Try reloading a page and adding a new todo. It should automatically place new one at the bottom of the list. All of the other operations that you perform on records should also work seamlessly, because we use standard +get()+ and +set()+ functions that work for every type of objects in SproutCore. +Last, our +clearCompletedTodos+ function needs to be updated to utilize the +destroy+ method available on +SC.Record+: + + + + // updating existing code + + Todos.todoListController = SC.ArrayController.create({ + + // ... + + clearCompletedTodos: function(){ + this.filterProperty('isDone', true).forEach( function(item) { + item.destroy(); + }); + }, + + // ... + + )}; + + +Try reloading a page and adding a new todo, marking a few as done and clicking the "Clear Completed Todos" button. It should automatically place new one at the bottom of the list and clear any completed when you click the button. All of the other operations that you perform on records should also work seamlessly, because we use standard +get()+ and +set()+ functions that work for every type of objects in SproutCore. h3. Changelog