Can I bind form inputs to models in Backbone.js without manually tracking blur events?

后端 未结 6 1491
抹茶落季
抹茶落季 2021-01-29 18:32

I have a backbone.js app (www.github.com/juggy/job-board) where I want to bind my form inputs directly to my model (a la Sproutcore).

Is it possible with Backbone.js (or

6条回答
  •  佛祖请我去吃肉
    2021-01-29 18:45

    I think this is a cleaner (and maybe faster) way to create an object from an input element

    changed: function(evt) {
      var target = $(evt.currentTarget),
          data = {};
      data[target.attr('name')] = target.val();
      this.model.set(data);
    },
    

    without jquery:

    changed: function(evt) {
      var target = evt.currentTarget,
          data = {};
      data[target.name] = target.value;
      this.model.set(data);
    },
    

提交回复
热议问题