在我看来,我不声明this.el因为我dinamically创建它,但在这样的事件不火。骨干刷新视图事件
这是代码:
视图1:
App.Views_1 = Backbone.View.extend({
el: '#content',
initialize: function() {
_.bindAll(this, 'render', 'renderSingle');
},
render: function() {
this.model.each(this.renderSingle);
},
renderSingle: function(model) {
this.tmpView = new App.Views_2({model: model});
$(this.el).append(this.tmpView.render().el);
}
});
查看2:
App.Views_2 = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'render');
},
render: function() {
this.el = $('#template').tmpl(this.model.attributes); // jQuery template
return this;
},
events: {
'click .button' : 'test'
},
test: function() {
alert('Fire');
}
});
});
当我点击 “.button” 什么也没有发生。 谢谢;
假设#模板包含一个带'.button'类的按钮,这应该起作用。你能发布你的#模板的内容吗? –