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

时间:2012-06-20 09:54:20

标签: javascript backbone.js marionette

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

1 个答案:

答案 0 :(得分:6)

如果使用Marionette视图类型上的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实例现在将取消绑定事件聚合器事件。