PDA

View Full Version : Issue with tree store - urgent help required



deepakpoda2000
10 Oct 2012, 3:47 AM
I have created a tree store, where I get the json data from a servlet..
but every time I expand a folder - the whole tree appears as a child

please see below code
var store1 = Ext.create('Ext.data.TreeStore', {
autoLoad: true,
autoSync: true,
proxy: {
type: 'ajax',
url: 'tree_servlet',
extraParams: {
isXml: true
},
success: function() {
console.log('success');
},
reader: {
type: 'json'
},
writer: {
type: 'json'
}
},
listeners : {
write : function(store, operation, eOpts) {
console.log('WRITE', arguments);}
},

root: {
text: 'Root Directory'/*,
id: 'src',
expanded: true*/
}
});

and the server side code is
JSON json = xmlSerializer.read( xml );
System.out.println(json.toString());
out.print(json);

Please let me know how I can proceed

sword-it
10 Oct 2012, 4:10 AM
Hi Deepak,

What is the return json data format from servlet ? It should be something like -


root: {
expanded: false,
children: [
{ text: "detention", leaf: true },
{ text: "homework", expanded: false, children: [
{ text: "book report", leaf: true },
{ text: "alegrbra", leaf: true}
] },
{ text: "buy lottery tickets", leaf: true }
]
}

deepakpoda2000
10 Oct 2012, 4:14 AM
my return data from servlet is as below. ie, output of System.out.println(json.toString()); is below[{"text":"ACME Washington DC","leaf":"true"},{"text":"Smith, Joe","leaf":"false"},{"text":"ACME Type 2 Rockets","description":"Defective Road Runner Rockets specifically for Coyotes ","leaf":"false"}]

deepakpoda2000
10 Oct 2012, 4:24 AM
to be more specific, this is what am doing in servlet

StringBuffer sc= new StringBuffer();
sc=sc.append("<nodes>");
sc=sc.append("<node>");
sc=sc.append("<text>ACME Washington DC</text>");
sc=sc.append("<leaf>true</leaf>");
sc=sc.append("</node>");
sc=sc.append("<node>");
sc=sc.append("<text>Smith, Joe</text>");
sc=sc.append("<leaf>false</leaf>");
sc=sc.append("</node>");
sc=sc.append("<node>");
sc=sc.append("<text>ACME Type 2 Rockets</text>");
sc=sc.append("<description>Defective Road Runner Rockets specifically for Coyotes </description>");
sc=sc.append("<leaf>false</leaf>");
sc=sc.append("</node>");
sc=sc.append("</nodes>");

String xml = sc.toString();
XMLSerializer xmlSerializer = new XMLSerializer();
JSON json = xmlSerializer.read( xml );
System.out.println(json.toString());
out.print(json);
should I be using out.println ????

scottmartin
10 Oct 2012, 4:47 AM
You have the data, but the result is not structured as show by sword-it.

Also ... why are you creating XML then converting it to JSON? Why not just build a JSON object directly?

Scott.

deepakpoda2000
10 Oct 2012, 4:52 AM
I want to store the structure of the tree in a database - and so am having an xml

which am converting to json object as below -

JSON json = xmlSerializer.read( xml );


is out.print the right way to send json object to extjs ?

deepakpoda2000
10 Oct 2012, 7:35 AM
root folder has "folder-A", "folder-B", "folder-C"

if am expanding "folder-A", am getting root folder's same elements/structure - ie., ( "folder-A", "folder-B", "folder-C")

please help

scottmartin
10 Oct 2012, 7:49 AM
What does your return JSON look like in your response tab ... verbatim

deepakpoda2000
11 Oct 2012, 8:22 AM
response from the server is as below
[{"text":"ACME Washington DC","leaf":"true"},{"text":"Smith, Joe","leaf":"false"},{"text":"ACME Type 2 Rockets","description":"Defective Road Runner Rockets specifically for Coyotes ","leaf":"false"}]


this is the response everytime I receive from the server every time I expand a folder