En mi opinión, no declaro this.el porque lo creo dinámicamente, pero de esta forma los eventos no se disparan.Backbone refresh ver eventos
Este es el código:
Vista 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);
}
});
Vista 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');
}
});
});
Cuando hago clic en ".button" no pasa nada. Gracias;
asumiendo el #template contiene un botón con una clase de '.button', esto debería funcionar. ¿puedes publicar los contenidos de tu #template? –