发布于 2012-12-04 14:32:45
是的,您仍然应该将close
方法添加到视图中。EventBinder并没有否定僵尸帖子所说的任何内容。相反,它使解除视图中所有事件的绑定变得更容易,从而有助于自动化许多过程。
请看一下Marionette.View源代码,了解它的用法:
https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view.js#L9 https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view.js#L16 https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view.js#L97
这是为你处理的。
如果您想将此代码添加到您自己的视图中,则很容易做到:
MyView = Backbone.View.extend({
initialize: function(){
// add the event binder
this.eventBinder = new Backbone.EventBinder();
// bind some stuff
this.eventBinder.bindTo(this.model, "change:foo", this.doStuff, this);
},
close: function(){
// ... other stuff
this.eventBinder.unbindAll();
}
});
https://stackoverflow.com/questions/13686165
复制相似问题