From 45c77f982910f1e65e1847016816716c1ee89995 Mon Sep 17 00:00:00 2001 From: Daniel X Moore Date: Tue, 20 Dec 2011 16:15:09 -0800 Subject: [PATCH] Fixed scoping on add item function to prevent appending to every ul element on the page. Only add items to the ul element within the view. --- 02/script.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/02/script.coffee b/02/script.coffee index 37fe1a5..acbdd5a 100644 --- a/02/script.coffee +++ b/02/script.coffee @@ -23,9 +23,12 @@ jQuery -> # `addItem()` will be called via the `click` event on the button we added # in our `render` method. + # The @$ function runs queries scoped within the view's element. This + # allows us to be sure we are only adding to the 'ul' element within + # this view. addItem: -> @counter++ - $('ul').append "
  • Hello, Backbone #{@counter}!
  • " + @$('ul').append "
  • Hello, Backbone #{@counter}!
  • " # [`events`](http://documentcloud.github.com/backbone/#View-delegateEvents) # is a JSON object where DOM events are bound to view methods. Backbone