-
28 Feb 2012 4:46 PM #1
TreePanel store reading different json format (4.0.7)
TreePanel store reading different json format (4.0.7)
Hi, currently I'm using XStream to convert Java objects into JSON, and it works fine for grids and everything else. The problem with using a treestore is that XStream's format (example 1) doesn't match ExtJs' (example 2) exactly. What is the best way to either tell the treestore how to read the different format, or at least reformat the json data as it comes during load()?
I can get closer if i fudge example 1 by changing the top name to "children" and having the root defined as '["children"]["NodeType"]' but it looks like it breaks when it gets to the final leaf with "Cannot read property 'NodeType' of undefined".
Thoughts?
Example 1: XStreams result, it wants to preface the array with the type of objects it holds, so if i send the data back it knows how to deserialize it.
Example 2: Works with ExtJs 4PHP Code:{
"data": {
"NodeType": {
"text": "1-1",
"leaf": false,
"children": {
"NodeType": [
{
"text": "1-0",
"leaf": false,
"children": {
"NodeType": [
{
"text": "1-0-0",
"leaf": true
}
]
}
}
]
}
}
}
}
Thanks in advance.PHP Code:{
"children": [
{
"text": "1-1",
"leaf": false,
"children": [
{
"text": "1-0",
"leaf": false,
"children": [
{
"text": "1-0-0",
"leaf": true
}
]
}
]
}
]
}
-
28 Feb 2012 5:26 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
It should place the NodeType key in there.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
28 Feb 2012 6:40 PM #3
Sorry, you are right, that isn't the exact xstream output, i had been messing with it for a while to see what would work and left it that way for demonstration purposes. Normally it produces "children": "". It does that with null or an empty arraylist as the contents of the attribute. This still causes the same problem though because it would try and access the NodeType object of children which doesn't exist. I tried injecting an empty object to satisfy that, but then it seemed like it failed trying to turn the empty object into children.
Last edited by maikhorma; 28 Feb 2012 at 6:41 PM. Reason: Cleaned up nbsp's caused by storing my message over a login due to timeout


Reply With Quote