我正在开发一个Backbone应用程序。我创建了一个父视图。每个视图都扩展了父级。但在我的情况下,声明性事件绑定不起作用。
var BaseView = Backbone.View.extend({
render: function () {
var model = this.model;
if(model instanceof Function) {
model = model();
}
var template = _.template(tpl.get(this.templateId), model);
this.$el.html(template);
if(this.postRender && this.postRender instanceof Function) {
this.postRender();
}
return this;
},
initialize : function (options) {
this.options = options || {};
}
});
var MainMenuView = BaseView.extend({
templateId: 'main-menu-tpl',
events: {
"click #prev" : "previous"
},
initialize: function(){
this.model = {
mainMenu: new MainMenu({title: 'CATEGORIES'})
};
},
initRender: function(menuItems){
this.model.mainMenu.set({"menuItems": menuItems});
return this.render();
},
previous: function(){
alert("Previous called");
}
});
我在这里做错了吗?