Model Savings Example

I created a list, but I have problems saving the model.

createOnEnter: function(e) { var self = this; var input = this.$("#new-title"); var input2 = this.$("#new-content"); //var msg = this.model.isNew() ? 'Successfully created!' : "Saved!"; if (!input || e.keyCode != 13) return; Mynote.save({title: this.input.val(), content: this.input2.val() }, { success: function(model, resp) { new LibraryView.Notice({message: msg}); self.model = model; self.render(); self.delegateEvents(); Backbone.history.saveLocation('mynotes/' + model.id); }, error: function() { new LibraryView.error(); } }); return false; }, 

Did I do it right? is it in the same view for the set or the "index" url or do I need to specify a different route for the new model?

+6
source share
1 answer

Instead Mynote.save you must have a line that:

 var note = new Mynote(); note.save({ tile: ..., content: .. }, { success: ..., error: ..}); 

See http://documentcloud.github.com/backbone/#Model-save

+8
source

Source: https://habr.com/ru/post/903588/


All Articles