Backbone.js的观看赛事禁用启用 [英] Backbone.js View events disable enable

查看:170
本文介绍了Backbone.js的观看赛事禁用启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个Backbone.js的查看和它在事件列表中的事件:

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

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

我怎么能那么禁用/启用该事件?因此,举例来说,如果它再点击
事件被删除(按钮保持在屏幕上,但灰色等)。当视图的某些其它部分被任何事件更新或
启用。当然,我可以使用jQuery,但我想知道,如果这个功能在骨干网是可用的。

How can I then disable/enable that event? So for instance if its clicked then the event is removed (the button remains on screen but is greyed out etc). When some other part of the view is updated or whatever the event enabled. Sure I can use jquery but I want to know if this functionality is available in backbone.

感谢您的任何答案

推荐答案

您可以随时使用 delegateEvents() undelegateEvents()来重做你的事件的DOM和你的骨干视图之间的结合。这就是说,我通常只是不停的事件处理程序,并添加一个条件在处理程序。

You can always use delegateEvents() and undelegateEvents() to redo your event binding between the DOM and your Backbone View. That said, I usually just keep the event handler and add a conditional in the handler.

// .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');
    }
}

然后你可以有你的另一种观点或code简单地 removeClass移除('禁用')当你想恢复功能。

更新 - disabled属性

请参阅评论,但一个更简单,更好的解决方案是使用禁用的属性禁用=禁用按钮。

See comments, but a simpler, much better solution is to use the disabled property disabled="disabled" of buttons.

这篇关于Backbone.js的观看赛事禁用启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆