Reputation: 319
i have generated a list but i have problems saving to 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 this correctly? its in the same view for the collection or 'index' url or do i need to specify a different route for the new model?
Upvotes: 6
Views: 17460
Reputation: 6710
Instead Mynote.save
you should have something line that:
var note = new Mynote();
note.save({ tile: ..., content: .. }, { success: ..., error: ..});
See http://documentcloud.github.com/backbone/#Model-save
Upvotes: 8