0
votes

I am doing a Model.load similar to this:

//get a reference to the User model class
var User = Ext.ModelManager.getModel('User');

//Uses the configured RestProxy to make a GET request to /users/123
User.load(123, {
    success: function(user) {
        console.log(user.getId()); //logs 123
    }

});

In the console I can see that the correct User object is being loaded. The correct server side web service is being called. It is going into the success function. However the user is undefined. Does anyone know why this would happen?

2
Well, ts hard to say without looking at your JSON response but i think the problem may be with the format of that JSON (maybe its not the root object, maybe its an array?) - VoidMain
@VoidMain the web service is returning a User object, the console shows a jsonarray {"id":22,"firstname":"ttes","lastname":"fff","phonenumber":"444-444-4444","email":"[email protected]","bio":"asdfsdfasdfdfs","travelradius":6,"accepted":true,"approver":null,"approvercomments":null} - Keenan Panitz
You say is showing a jsonarray but your json looks like a single object, if it is an array response then you need to unwrap that in your server to get only one result when you load by id (like in your example) the load method takes a single result object, not an array, may that be your case? In any case it would be usefull to see you proxy and reader config for that model. - VoidMain

2 Answers

0
votes

From your description, the console is showing a user object (which is just a bunch of key/value pairs in a JSON response).
You say user is undefined, but it looks like you mean user.getId() is undefined.
The JSON response from the web server doesn't have any methods on it (like getId) - just key/value pairs.

EDIT: Your code looks a lot like the example given here (about mid-way down).
If you modify your logging to say this:

console.log("User: " + user.get('firstname'));

does it return ttes like you show in your JSON object?

0
votes

This is a shot in the dark an might not be the correct answer.

I believe you are not returning the correct JSON. First, it will be useful to see the proxy definition on the model, and if you have set any root property in its reader.

If you haven't defined any reader root, then try to warp your JSON response with [ and ].

If any of this works I'll explain why.