Backbone.js View Event Disablements

If I have a view in backbone.js and it has an event in the event list:

events: {
    'click #somebutton': 'clicked'         
},
clicked: function () {
    console.log('clicked');
}

How can I disable / enable this event? So, for example, if you click it, the event is deleted (the button remains on the screen, but is inactive, etc.). When some other part of the view is updated or something is turned on in this case. Of course, I can use jquery, but I want to know if this functionality is available in the trunk.

Thanks for any answers.

Floor

+2
source share
2 answers

delegateEvents() undelegateEvents() DOM Backbone View. , .

// .disabled class (CSS) grays out the button

clicked: function(event) {
    var buttonEl = $(event.currentTarget);

    if (buttonEl.hasClass('disabled')) {
        // Do nothing
    } else {
        // Do something AND...
        buttonEl.addClass('disabled');
    }
}

removeClass('disabled'), .

UPDATE -

. , disabled="disabled" .

+2

delegateEvents undelegateEvents . : delegateEvents

+2

Source: https://habr.com/ru/post/1524323/


All Articles