Created
February 26, 2013 11:04
-
-
Save collingo/5037704 to your computer and use it in GitHub Desktop.
Backbone Month, Week 3, Views - completed code
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
var TodoListView = Backbone.View.extend({ | |
tagName: "ul", | |
id: "todolist", | |
initialize: function() { | |
_.bindAll(this, "appendTodo"); | |
}, | |
render: function() { | |
this.$el.empty(); | |
this.collection.each(this.appendTodo); | |
return this; | |
}, | |
appendTodo: function(todo) { | |
this.$el.append(new TodoListItemView({ | |
model: todo | |
}).render().el); | |
} | |
}); | |
var TodoListItemView = Backbone.View.extend({ | |
tagName: "li", | |
className: "item", | |
template: _.template('<p><%= description %> <input type="checkbox" name="checked" value="true"></p>'), | |
render: function() { | |
this.$el.empty().append(this.template(this.model.toJSON())); | |
return this; | |
} | |
}); | |
var todoListView = new TodoListView({ | |
collection: myTodoList | |
}); | |
$("body").prepend(todoListView.render().el); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment