Theo quan điểm của tôi, tôi không khai báo điều này.el vì tôi tạo ra nó theo thực tế, nhưng theo cách này các sự kiện không cháy.Các sự kiện xem làm mới xương sống
Đây là mã:
Xem 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);
}
});
View 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');
}
});
});
Khi tôi bấm vào ".button" có gì xảy ra. Cảm ơn;
giả định #template chứa nút có lớp '.button', thao tác này sẽ hoạt động. bạn có thể đăng nội dung của #template của mình không? –