I have a basic base model, its urlRoot attribute urlRoot set, and the corresponding server-side target returns the correct JSON output (both the JSON string and the application/json header).
I call the selection as follows:
var athlete = new Athlete({ id: 1 }); athlete.fetch();
at this point if i add
console.log(athlete);
I can see the model and test it in firebug. I can open the attribute object and see all the values ββreturned from the server.
BUT if I do a:
console.log(athlete.get('name'));
I get undefined (the name appears under the attributes in the DOM check mentioned above)
also performs:
console.log(athlete.attributes);
returns an object containing only {id: 1} , which is the argument that I passed when creating the model.
If I create a model as follows:
var athlete = new Athlete(<JSON string copypasted from the server response>);
then everything works fine, the .get() method returns everything I ask, and athlete.attributes shows all the values.
What am I doing wrong?
Matteo iva
source share