I’m writing an app with node.js and backbone.js. However when I try to save a model it is nesting the JSON of the model inside a model dictionary.
node = new NodeModel({prop1:"value1", prop2:"value2"});
node.save();
The results of console.log(req.body); inside my node controler show…
{model: {"prop1":"value1", "prop2":"value2"} }
If i use a standard html form to post to the same node controller the results of console.log(req.body); show…
{prop1:"value1", prop2:"value2"}
How can i get the node.save(); function to post the same JSON that the regular HTML does?
Looks like you have Backbone configured to emulate JSON:
and the corresponding chunk of
Backbone.synclooks like this:You can see the
model.toJSON()call in the firstif, themodel:prefix comes in in the secondif. You should be able to saysomewhere in your application setup (after Backbone is loaded, before you try to sync anything) and the
model:business will go away.