Javascript 取消绑定视图添加到app.vent的所有事件
通过调用Javascript 取消绑定视图添加到app.vent的所有事件,javascript,backbone.js,marionette,Javascript,Backbone.js,Marionette,通过调用view.unbindAll(),我添加到全局事件总线的事件是否会被删除?如果在木偶视图类型上使用bindTo方法绑定它们,则是: SomeView = Backbone.Marionette.ItemView.extend({ initialize: function(){ // note the use of the 4th parameter. this is important when binding // to the App's event aggr
view.unbindAll()
,我添加到全局事件总线的事件是否会被删除?如果在木偶视图类型上使用bindTo
方法绑定它们,则是:
SomeView = Backbone.Marionette.ItemView.extend({
initialize: function(){
// note the use of the 4th parameter. this is important when binding
// to the App's event aggregator
this.bindTo(MyApp.vent, "some:event", this.someCallback, this);
},
someCallback: function(){
// ...
}
});
关闭SomeView实例将立即解除事件聚合器事件的绑定。谢谢。顺便说一句,我真的可以传递someCallback,而不是这个.someCallback吗?哦,不。
this.someCallback
。。。早上太早了还有一个小问题,我需要把它作为上下文来传递吗?它不是默认的上下文吗?bindTo现在被listenTo替换:我尝试了listenTo()
与MyApp.vent绑定,并且我必须在close()
函数中手动stopListening()
。我应该如何注册事件,以便在视图关闭时,事件自动解除绑定?注意:我使用的是木偶v1.0.1