Add Backbone models, collection, views

This commit is contained in:
Abhishek Das
2013-03-24 23:22:54 +05:30
parent 452da3f610
commit edee63c452
8 changed files with 151 additions and 56 deletions
+26
View File
@@ -0,0 +1,26 @@
var app = app || {};
(function() {
app.ListView = Backbone.View.extend({
el: $("#main .children"),
initialize: function(initialTasks) {
this.collection = new app.List(initialTasks);
this.render();
},
render: function() {
this.collection.each(function(task) {
this.renderTask(task);
}, this);
},
renderTask: function(task) {
var taskView = new app.TaskView({
model: task
});
this.$el.append(taskView.render().el);
}
});
}());
+18
View File
@@ -0,0 +1,18 @@
var app = app || {};
(function() {
app.TaskView = Backbone.View.extend({
tagName: 'li',
template: $('#taskTemplate').html(),
render: function() {
var tmpl = _.template(this.template);
this.$el.html(tmpl(this.model.toJSON()));
return this;
}
});
}());