Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backbone model save example

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?

like image 377
user901790 Avatar asked Dec 12 '11 13:12

user901790


People also ask

How do you save in Backbone?

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.

Is Backbone JS still used?

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.

Is Backbone a MVC?

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).

Which of the following is the correct syntax for creating Backbone view?

js view class to create a custom view. Syntax: Backbone. View.


1 Answers

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

like image 107
luacassus Avatar answered Sep 30 '22 16:09

luacassus