Dal mio punto di vista non lo dichiaro.el perché lo creo dinamicamente, ma in questo modo gli eventi non sparano.Backbone refresh view eventi
Questo è il codice:
View 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');
}
});
});
Quando clicco su "apri un" non succede nulla. Grazie;
assumendo la #template contiene un pulsante con una classe di 'apri un', questo dovrebbe funzionare. puoi pubblicare il contenuto del tuo #template? –