From 13b987bccd689a6fccd703d3d43df314f665198a Mon Sep 17 00:00:00 2001 From: norly Date: Sun, 25 Jan 2015 10:59:12 +0800 Subject: [PATCH] Update 02-fundamentals.md As I go trough this chapter, I tried an d run the first example (trying todoView.render in the console) but I noticed that li is not being used as I inspect the element. So i removed use of li because the $el is already being set into div element by the following: this.$el = $('#todo'); --- chapters/02-fundamentals.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/chapters/02-fundamentals.md b/chapters/02-fundamentals.md index edbcc1ce..5c3ee35b 100644 --- a/chapters/02-fundamentals.md +++ b/chapters/02-fundamentals.md @@ -142,8 +142,6 @@ Each Todo instance will be rendered on the page by a TodoView: ```javascript var TodoView = Backbone.View.extend({ - tagName: 'li', - // Cache the template function for a single item. todoTpl: _.template( $('#item-template').html() ), @@ -194,7 +192,7 @@ var TodoView = Backbone.View.extend({ var todoView = new TodoView({model: myTodo}); ``` -TodoView is defined by extending Backbone.View and is instantiated with an associated Model. In our example, the ```render()``` method uses a template to construct the HTML for the Todo item which is placed inside an li element. Each call to ```render()``` will replace the content of the li element using the current Model data. Thus, a View instance renders the content of a DOM element using the attributes of an associated Model. Later we will see how a View can bind its ```render()``` method to Model change events, causing the View to re-render whenever the Model changes. +TodoView is defined by extending Backbone.View and is instantiated with an associated Model. In our example, the ```render()``` method uses a template to construct the HTML for the Todo item which is placed inside the view's $el(this is set in the initialize method as $('#todo')). Each call to ```render()``` will replace the content of the $('#todo') using the current Model data. Thus, a View instance renders the content of a DOM element using the attributes of an associated Model. Later we will see how a View can bind its ```render()``` method to Model change events, causing the View to re-render whenever the Model changes. So far, we have seen that Backbone.Model implements the Model aspect of MVC and Backbone.View implements the View. However, as we noted earlier, Backbone departs from traditional MVC when it comes to Controllers - there is no Backbone.Controller!