【问题标题】:Backbone.js ModelBinder change default event to keyupBackbone.js ModelBinder 将默认事件更改为 keyup
【发布时间】:2012-08-24 16:43:59
【问题描述】:

在我的 Backbone.js 应用程序的开发过程中 - 我注意到我的视图中有很多样板代码,所以我决定搜索一个模型绑定器库,

最好的选择似乎是: Backbone.ModelBinder

...但问题是它不允许我从默认的“模糊”事件切换到内容可编辑输入的“keyup”。

我尝试修改库的源代码,但它有点忽略了我的 2 个从“模糊”到“keyup”的内容可编辑字段的更改,并且仍然退回到“模糊”事件。

有没有人遇到过类似的问题或者可以帮助我解决这个问题?

非常感谢。

【问题讨论】:

    标签: javascript events backbone.js observer-pattern


    【解决方案1】:

    您在源代码中的哪个位置进行了更改?

    我已尝试编辑此 commit 中看到的两行,它可以工作...

        _bindViewToModel:function () {
            $(this._rootEl).delegate('', 'change keyup', this._onElChanged);
            // The change event doesn't work properly for contenteditable elements - but blur does
            $(this._rootEl).delegate('[contenteditable]', 'blur keyup', this._onElChanged);
        },
    
        _unbindViewToModel: function(){
            if(this._rootEl){
                $(this._rootEl).undelegate('', 'change keyup', this._onElChanged);
                $(this._rootEl).undelegate('[contenteditable]', 'blur keyup', this._onElChanged);
            }
        },
    

    【讨论】:

    • 我只更改了内容可编辑的行,并用 keyup 替换了 blur,太棒了!!!!谢谢!!
    猜你喜欢
    • 1970-01-01
    • 2014-01-03
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多