Skip to content Skip to sidebar Skip to footer

Backbone Not Making A Put Request With Save() After Save

I am experiencing a really interesting problem with backbone, I have a function like this in one of my views: addpeople :function(){ var authArray = _.clone(this.model.get

Solution 1:

The reason why change didn't trigger for your second example is because it is the same object and Backbone ignore it. Hence no change event triggered.

As for why the first one failed; do you have validator for your model? May be something that validating for empty string perhaps? val() can return an empty string and split() on empty string will return [""]

Also, your defaults should be a function otherwise all your model would have the same instance of comments, tags and authorizedUsers

From Backbone doc.

Remember that in JavaScript, objects are passed by reference, so if you include an object as a default value, it will be shared among all instances. Instead, define defaults as a function.

Arrays are object too.

varPostModel = Backbone.Model.extend({
    urlRoot : '/tweet',
    idAttribute: '_id',
    defaults: function(){
      return {
          name: '',
          comments: [],
          tags: [],
          authorizedUsers: [],
          postedBy : '',
          dateCreated: ''
      }
  }
});

Lastly, array.forEach() is not available on IE8 and older.

Post a Comment for "Backbone Not Making A Put Request With Save() After Save"