View Full Version : TreeStore problems loading nested data from web service

2 Nov 2011, 9:09 AM
I'm having trouble loading a TreeStore from nested data returned from a web service. None of the nodes get populated if the node data is contained in a top level property of the response object. There is no problem if the node data IS the response object. How can I get the following scenario to load a TreeStore properly?

Using the TreeGrid example in the API docs, consider wrapping the existing TreeGrid.json content in the following structure:

"payload": <!-- TreeGrid.json content here -->,

Again, using the TreeGrid example, I'm using the following definition for my TreeStore:

store = Ext.create('Ext.data.TreeStore', {
model: 'Task',
proxy: {
type: 'ajax',
//the store will get the content from the .json file
url: 'treegrid.json',
reader: {
type: 'json',
root: 'payload'
folderSort: true

I'm guessing that once I set the reader's root it's looking for a "payload" property instead of "children" property to identify all child nodes. If so, does this mean we can't wrap TreeStore data in a response object that includes additional information about the request and can only return the tree itself? This is a big problem for me (and I assume many corporate users) as we have a standard payload wrapper that is used for json responses from every web service call.

If I'm overlooking something here help would be appreciated.

2 Nov 2011, 9:20 AM
Yes, nested data is under the same property as the root.

3 Nov 2011, 5:02 AM
Thanks for the response tvanzoelen.

So the Ext designers never considered a top level wrapper for tree/node data? Seems like a major oversight that will preclude many corporate developers from using the TreeStore with remote json services.

There should be some type of json node reader for TreeStore that has not just a root property but also a nodeRoot property where root would be the location of the root node and the nodeRoot would be where the nodes are defined under the root node. The root property works as expected for tabular data with the Store.

2 Dec 2011, 11:57 AM
This is a major flaw in my eyes! Most json responses (REST-proxies, Ajax-forms) require a "top-level-wrapper" around the actual data. Why should this be different when working with tree stores? If my top-level root-element is different than the "child-node" the tree store is unusable!

"data": {
"text": "foo",
"children": [
"text": "baz",
"children": []
}, {
"text": "bazbar",
"children": []
"message": "working",
"success": true
This has to work!