Skip to content Skip to sidebar Skip to footer

How To Set Backbone.js To Include Model Name In JSON Post?

I've been working on a Backbone.js project that syncs to a Google App Engine REST server I've also put together. I'm using the Appengine-Rest-Server project code to enable the REST

Solution 1:

Most elegant way:

YourModel = Backbone.Model.extend({

   name: 'modelName',

   toJSON: function () {
       var data = {};

       data[this.name] = _.clone(this.attributes); // or Backbone.Model.prototype.toJSON.apply(this)

       return data;
   }

});

Or you can directly pass data to the options

model.save(null, {
    data: {
       // custom format
    }
});

Post a Comment for "How To Set Backbone.js To Include Model Name In JSON Post?"