-
25 Jul 2011 6:28 AM #1
JSON - AJAX - Treestore
JSON - AJAX - Treestore
Hello,
i want to load a complete Tree with ajax at once. My get-tree.php returns following json:
My app.js looks like:Code:{"root":{"expanded":true,"children":[{"text":"Suche","leaf":true},{"text":"Projekt","expanded":true,"children":[{"text":"Planung","leaf":true},{"text":"Pruefung","leaf":true}]},{"text":"Abmelden","leaf":true}]}}
The local static store works but the ajax store does not. What is wrong with it?Code:Ext.onReady(function() { /*var store = Ext.create('Ext.data.TreeStore', { root: { expanded: true, children: [ { text: "Suche", leaf: true }, { text: "Projekt", expanded: true, children: [ { text: "Planung", leaf: true }, { text: "Pruefung", leaf: true} ] }, { text: "Abmelden", leaf: true } ] } });*/ var store = Ext.create('Ext.data.TreeStore', { proxy: { type: 'ajax', url : 'get-tree.php', reader: { type: 'json', root: 'children' } } }); Ext.create('Ext.Viewport', { renderTo: Ext.getBody(), border: false, layout: { type: 'border', padding: 5 }, items: [{ xtype:'treepanel', region:'west', title:'Navigation', width: 200, height: 150, store: store, rootVisible: false, margins: '5 0 0 0', cmargins: '5 5 0 0', collapsible: true, width: 175 },{ region:'center', margins: '5 0 0 0', xtype: 'panel', title: 'main', id: 'main', html: 'Willkommen' }] }); })
Thanks for the help.
-
25 Jul 2011 7:01 AM #2
try the config option in your store
autoLoad: true
-
25 Jul 2011 11:01 PM #3
Thanks for the answer.
With autoLoad:true its the same. The treepanel is just empty.
With firebug i see the call from get-tree.php and the answer with the valid json.
-
25 Jul 2011 11:16 PM #4
I noticed you don't have a root node hanging in your tree. I guess yor problem will be solved when adding a root node into your store or tree. Did it not complain about missing root node?
-
25 Jul 2011 11:54 PM #5
Ok, i have solved the problem.
The Json has to look like this:
Please close this Thread.Code:{"text":".","children": [ { text:'Suche', leaf:true, iconCls:'text' },{ text:'Projekte', iconCls:'text-folder', children:[{ text:'Planung', leaf:true, iconCls:'text' },{ text:'Pruefung', leaf:true, iconCls:'text' }] },{ text:'Abmelden', leaf:true, iconCls:'text' } ]}
-
9 Feb 2012 1:19 AM #6
Same problem, tried your solution, but did not work
Same problem, tried your solution, but did not work
Hi, I am facing the same problem since last 1 week, but not managed ot tackle it yet. I have taken your identical js file, and passed a minimized string back, with values based on what you have suggested: something like
return "{\"text\":\".\",\"children\": [ { text:'Suche', leaf:true, iconCls:'text' }]}";
But this basic string is also not taken in correctly and the navigation panel on the left remains empty. Please suggest what could be wrong.
When I see in firebug, the returned json shows up for "d":
"{"text":".","children": [ { text:'Suche', leaf:true, iconCls:'text' }]}"
-
9 Feb 2012 2:51 AM #7
u can try this
Code:var jsonDecode = Ext.JSON.decode(response.responseText).d; var decode = Ext.decode(jsonDecode); alert(decode.msg);
-
9 Feb 2012 7:31 PM #8
Thanks, you pointed the correct option
Thanks, you pointed the correct option
Thanks for your suggestion which is correct. I had meanwhile implemented using solution an an earlier form, on the same lines as your suggestion, and that worked http://www.sencha.com/forum/showthre...-service/page2
-
10 Oct 2012 2:04 PM #9


Reply With Quote
