user901790
user901790

Reputation: 319

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?

Upvotes: 6

Views: 17460

Answers (1)

luacassus
luacassus

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

Related Questions