javascript - How to save input values in a Backbone model -
currently i'm running situation when need grab 1 value selected option , value of 1 input , save in backbone model , save on server. here's markup:
<select id="select" multiple size=5> <option value="room" name="room">room</option> <option value="teacher" name="teacher">teacher</option> <option value="group" name="group">group</option> </select> <input type="text" name="name"> <button type="button" class="save">save</button>
by clicking on save button want store current 2 values in model. tried plugin modelbinder backbone, think use in wrong way.
var createeditview = backbone.view.extend({ tagname: 'div', template: editresourcetpl, events: { 'click .save': 'save', }, initialize: function () { this.modelbinder = new backbone.modelbinder(); }, render: function () { this.$el.append(this.template()); this.modelbinder.bind(this.model, this.el); return this; }, save: function () { var isnewmodel = this.model.isnew(); this.model.once('sync', function () { if (isnewmodel) { vm.mediator.publish('resourcesaved', this.model); } }, this); this.model.save(); } });
can please give me right direction of how can this? need gather 2 values form (1 selected option , 1 input), store in model , save on server (and yet pass model through mediator). how can use modelbinder plugin here in correct way achieve this? appreciated.
option
not have property name
. should assign name
select
.
https://developer.mozilla.org/en-us/docs/web/html/element/select
https://developer.mozilla.org/en-us/docs/web/html/element/option
Comments
Post a Comment