I have a model called User which, when I do a Fetch, would ideally expect to receive a JSON object that looks like this:
{"UserId":"20","FirstName":"Test","SurName":"User"}
But the object that comes back, and that I need to work with, looks like this:
{
"Type": "Single",
"Error: "",
"Objects": {
"UserId":"20",
"FirstName":"Test",
"SurName":"User"
}
}
This is likely to be true for all of the models in my application.
What’s the best way to tell the models to populate themselves from the Objects object rather than the root object?
Apologies if my question isn’t as clear as it could be: I’m a Backbone virgin and this is all new to me.
You need to override the
parsemethod of your model.See Backbone documentation for Model.parse.