PDA

View Full Version : need model and json reading help



nschef
23 Jul 2010, 2:42 PM
Here's my problem... I have complex json coming back, here's a simple example of what I'm dealing with:



// The json I'm getting back is one object with nested objects and lists of objects.

{
"id":1,
"result":{
"myprop1":"myvalue1",
"myListOjbect":{
"class":"someclass",
"list":[{"prop1": "value1"}]
},
"myObject":{
"objProp1":"objVal1"
}
}
}

//my model is like this
Ext.regModel('MyModel', {
fields: [
{name:'myprop1', type:'string'}
// mapping my other objects and lists later.
]
});
Let's say right now I don't even care about this subclass list of "myListOjbect" or the nested object "myObject". I just want "myprop1" set to my model. I am using a json reader and I do not set the root because there is none here, the json I want to make to my model is nested in "result{}". The problem is that it does not read this because it's not a json list, that's my best guess at this point. When I debug through the code I can see the data from the json call and it looks good, but it looks like it will only map an array to the object. I then print out the record number in my callback after load and it always comes back with 0.

I have had no issues when the json I am getting back is a list of pojos like this and I set my root to "list":


{
"id":1,
"result":{
"class":"someclass",
"list":[{"prop1": "value1"}]
}
}

//my model is like this
Ext.regModel('MyModeThatWorksl', {
fields: [
{name:'prop1', type:'string'}
]
});

// my store will have 1 record in it
To break it down how could I read my model and just ignore the sub components for now?

Are there any examples of complex models or associations between models anywhere? I would appreciate any help on this one. I was going to write my own reader, but I want to be sure there's nothing to handle these kinds of things so I don't reinvent any wheels.

jep
20 Jan 2011, 9:53 PM
FYI:
http://www.sencha.com/forum/showthread.php?121668-return-json-data-where-root-is-not-an-array