Backbone ModelBinder文本字段的keyup事件问题

时间:2016-04-26 06:28:36

标签: javascript backbone.js modelbinders

有一个简单的表格

<script type="text/template" id="app1">
<div id="form1">
    <label>Name: </label>
    <input type="text" id="txtName" /><br />

    <input type="button" id="btnSubmit" value="Submit" />
</div>
</script>

var infoModel = Backbone.Model.extend({});

var model = new infoModel();
model.bind('change', function(){
    model.save();
});

var appView = Backbone.View.extend({
    model: model,
    _modelDataBind: undefined,
    initialize: function(){
        this._modelDataBind = new Backbone.ModelBinder();
        this.render();
    },
    render: function(){
         var template = _.template($('#app1').html());
         this.$el.html(template);
         var bindings = {
            name: '#txtName'
         };
         var changeTrigger = {
             'changeTriggers': {
                  '': 'keyup',
                  'input[type=text]': 'keyup'

              }
         };
         this._modelDataBind.bind(this.model, this.$el, bindings, changeTrigger);
    }
});

但是这会触发模糊操作的更改事件而不是键盘

0 个答案:

没有答案