取消绑定视图添加到app.vent的所有事件

And*_*rle 4 javascript backbone.js marionette

我通过调用删除了添加到全局事件总线的事件view.unbindAll()吗?

Der*_*ley 6

如果使用bindToMarionette视图类型上的方法绑定它们,是:


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(){
    // ...
  }
});
Run Code Online (Sandbox Code Playgroud)

现在,关闭SomeView实例将取消绑定事件聚合器事件.