我看过这个问题,但在重新渲染后我仍然无法维护子视图的事件。我试图在这里重新创建我的问题:
var MainView = Backbone.View.extend({
initialize : function() {
this.composer = new Composer();
},
render : function() {
this.$el.html(this.composer.render().el);
}
});
var SubView = Backbone.View.extend({
tagName: 'li',
events: {
"click": "click"
},
click: function(){
console.log( "click!" );
},
render: function(){
this.$el.html( "click me" );
return this;
}
});
var Composer = Backbone.View.extend({
tagName : 'ul',
render: function(){
console.log( "Composer.render" );
this.$el.empty();
for (var i = 0; i < 5; i++) {
var sub = new SubView();
this.$el.append( sub.render().el );
}
sub.delegateEvents();
return this;
}
});
在示例中,重新渲染视图会禁用子视图中的点击事件。我不确定为什么这不起作用。