0

I want to update a backbone model so that I can set the data of a backbone model and then update it on the express backend but so far I have not been successful. I have checked the urls on the routes and it is correct but so far it has not been sent to the backend.

Here is the update part of the code.

update: function() {
    this.$('#noteParent .note-editable').prop('contenteditable', false);
    this.$('#aboutParent .note-editable').prop('contenteditable', false);
    this.$('#update').prop('disabled', true);
    var notes = this.$('#noteParent .note-editable').html();
    var about = this.$('#aboutParent .note-editable').html();
    var username = $('#data-username').text();
    app.url = "/update-usernotes";
    this.model.set({
        username: username,
        email: app.email,
        about: about,
        editorNote: notes
    });
} 

Is the set method the right method to update the model ? Also on doing console.log(this.model) right before this.model.set i get the updated model, so how can I send the updates to the backend ?

Nurdin
  • 23,382
  • 43
  • 130
  • 308
Bazinga777
  • 5,140
  • 13
  • 53
  • 92

2 Answers2

1

set make changes locally to model , when you want to make a request to to backend use save

 this.model.save({                        
                        username: username,
                        email: app.email,
                        about: about,
                        editorNote: notes   
                },{})
StateLess
  • 5,344
  • 3
  • 20
  • 29
0

use this.model.save for database operations for more http://backbonejs.org/#Model-save

Kiran Shinde
  • 5,732
  • 4
  • 24
  • 41