Вопрос

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?

Это было полезно?

Решение 2

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
}

Другие советы

I would have a property on the view. Something like this:

var View = Marionette.ItemView.extend({
    initialize: function() {
        this.clickEnabled = true;
    },
    events: {
        'click': 'clickContainer'
    },
    clickContainer: function() {
        if ( this.clickEnabled ) {
           // do stuff
        }
    }
});

then you just change that property when you want to change the state.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top