javascript - model.save - saves to the server only once -
i running code in backbone saves data server,
groupmodalheaderview.prototype.save = function(e) { var $collection, $this; if (e) { e.preventdefault(); } $this = this; if (this.$("#group-name").val() !== "") { $collection = this.collection; if (this.model.isnew()) { console.log("model new"); this.collection.add(this.model); } return this.model.save({ name: this.$("#group-name").val()}, { async: false, wait: true, success: function() { //console.log($this, "this"); console.log('successfully saved!'); this.contentview = new app.groupmodalcontentview({ model: $this.model, collection: $this.collection, parent: }); this.contentview.render(); return $this.cancel(); }, }); } };
this works fine first time run it, if run again straight after saving first piece of data not save new data merely updates last saved data. first time save runs post request , next time runs put request, why be?
i not sure if need here initialise function -
groupmodalheaderview.prototype.initialize = function() { _.bindall(this) }
your view has model object attached it. understand fill forms, put data model , save model. time have single model object, , update it's data. if want create new object after saving model add line:
this.model = new yourmodelclass();
right after line console.log('successfully saved!');
Comments
Post a Comment