Backbone.js ModelBinder将默认事件更改为keyup

Backbone.js ModelBinder change default event to keyup

本文关键字:keyup 事件 默认 js ModelBinder Backbone      更新时间:2023-09-26

在我的Backbone.js应用程序的开发过程中,我注意到我的视图中有很多样板代码,所以我决定搜索Model Binder库

最佳选择似乎是:Backbone.ModelBinder

但问题是,对于内容可编辑的输入,它不允许我从默认的"blur"事件切换到"keyup"。

我试图修改库的源代码,但它有点忽略了我对内容可编辑字段从"blur"到"keyup"的2次更改,并且仍然返回到"blur"事件。

有没有人经历过类似的问题,或者也许可以帮助我解决这个问题?

非常感谢。

您在源代码中的哪些地方进行了更改?

我试着编辑了这篇文章中的两行,效果很好。。。

    _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);
        }
    },