在我看來,我不聲明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'類的按鈕,這應該起作用。你能發佈你的#模板的內容嗎? –