我正在学习Addy Osmani 的开发 Backbone.js 应用程序,但我被卡住了。
这是我的看法:
var TodoView = Backbone.View.extend({
tagName: 'li',
className: 'todo_list',
todoTpl: _.template($('#item-template').html()),
events:{
'dblclick label': 'edit',
'keypress .edit':'updateOnEnter',
'blur .edit':'closed'
},
initialize:function(){
_.bindAll(this, 'edit','render','updateOnEnter','closed');
this.render();
},
render: function(){
this.$el.html(this.todoTpl(this.model.toJSON()));
this.input = this.$('.edit');
return this;
},
edit: function(){},
updateOnEnter: function(){},
closed: function(e){}
});
var todoView = new TodoView();
console.log(todoView.el);
这是我的错误:
TypeError: this.model is undefined
this.$el.html(this.todoTpl(this.model.toJSON()));
我哪里错了?