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?
Backbone is wonderful because it does a lot of work for you. To save our donut and secondHelping, we simply do this: myDonut. save(); mySecondHelping.
Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.
Backbone. js is a model view controller (MVC) Web application framework that provides structure to JavaScript-heavy applications. This is done by supplying models with custom events and key-value binding, views using declarative event handling and collections with a rich application programming interface (API).
js view class to create a custom view. Syntax: Backbone. View.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With