PDA

View Full Version : Setting a root node name for the JSON for treepanel store



pinidbest
16 Aug 2012, 2:30 AM
Hi all,
I have a treepanel controll that is connected to a "Ext.data.TreeStore"
Since I want to add to the responce from the server (JSON) another property to specify something I need a way to tell the store to look for the first root somewhere else in the returning JSON.

How do I do that?

friend
16 Aug 2012, 3:58 AM
The proxy of your TreeStore contains a reader. The reader allows you to declare a root property which identifies the JSON node that is the starting point for your tree data:



proxy: {
type: 'ajax',
url : 'treeDataUrl',
reader: {
type: 'json',
root: 'rootNameHere'
}
}

pinidbest
16 Aug 2012, 4:05 AM
I have already tried that and it doesnt work

friend
16 Aug 2012, 4:12 AM
If you would, please post one of your JSON responses which includes the custom property you're adding.

pinidbest
16 Aug 2012, 4:38 AM
Hi,
Here is the working JSON
{"Term":".","qtip":null,"CorrelationLevel":0,"leaf":false,"children":[{"Term":"folders","qtip":"","CorrelationLevel":2,"leaf":true,"children":.....

And once I am wrapping it like this:{"QuerySuggestions":{"Term":".","qtip":null,"CorrelationLevel":0,"leaf":false,"children":[{"Term":"folders","qtip":"","CorrelationLevel":2,"leaf":true,"children":...

And setting the root like to mentioned:


reader: { type: "json" , root: "QuerySuggestions" },It displayed a "." as the root which I need to open in order to watch the tree.

friend
17 Aug 2012, 4:58 AM
As a test, change the value of the QuerySuggestions property to be an array:



{"QuerySuggestions": [{"Term":".","qtip":null,"CorrelationLevel":0,"leaf":false,"children":[{"Term":"folders","qtip":"","CorrelationLevel":2,"leaf":true,"children":...]

pinidbest
18 Aug 2012, 9:16 PM
The tree look bad and calling to the web method again and agian and create child nodes that should not be under certain nodes.

It looks like a bug

pinidbest
18 Aug 2012, 9:17 PM
Is there an event on the treepanel that is like a onitembind so I can add my wanted property as a node and know how to ignore it when rendering the items?

vietits
19 Aug 2012, 1:07 AM
No still no good


The tree look bad and calling to the web method again and agian and create child nodes that should not be under certain nodes.


It looks like a bug

You have config root: 'QuerySuggestions', so let try to change all 'children' to 'QuerySuggestions' in your json data, like below:


{
"QuerySuggestions": [{
"Term":".",
"qtip":null,
"CorrelationLevel":0,
"leaf":false,
"QuerySuggestions":[{
"Term":"folders",
"qtip":"",
"CorrelationLevel":2,
"leaf":true,
"QuerySuggestions":

pinidbest
19 Aug 2012, 11:24 PM
Thanks