Search code examples
eventsbackbone.jsbindunbindmarionette

How to bind and unbind mouse events on Marionette


I have this event in my view:

    events:
        "click" : "clickContainer"

How can I unbind/bind (able and disable) temporary the click event in the same View?


Solution

  • Another option is to remove the events map and use the manual version of what the events map sets up.

    onShow: function() {
      this.enableClick();
    },
    
    enableClick: function() {
      $(".clickContainer").on("click", this.onClickContainer);
    },
    
    disableClick: function() {
      $(".clickContainer").off("click", this.onClickContainer);
    },
    
    onClickContainer: function() {
      // do stuff
    }