PDA

View Full Version : "Massaging" json before it's loaded into a TreePanel



MrKurt
12 Apr 2007, 7:32 AM
What's the best way to translate a json response prior to it being loaded into a TreePanel? It doesn't look like you can use a datastore on a tree, unfortunately. Should I make my own custom Treeloader to handle it?

tryanDLS
12 Apr 2007, 8:55 AM
It depends on the point at which you need to do something with the response. TreeLoader.processResponse builds the nodes, then can execute your callback to do more, or you can add a handler for the load event, which fires after processResponse.

If you need to do something with the response before nodes are built, you probably want to just override processResponse with your own version. Or, you might just override the CreateNode method with your own implementation. It kind of depends on how much/where you need to tweak the response.

simeon
12 Apr 2007, 9:39 AM
you can get your json via a traditional ajax response, modify it and then pass to the asynchTreeNode.



//Edit responseDataNode needs to be an array
responseDataNode = [{"text":'text here'}];

responseTree = new Ext.tree.TreePanel('ComposeEditorCenterRightBody_div', {
animate:true,
enableDD:true,
loader: new Ext.tree.TreeLoader(),
containerScroll: true,
ddGroup: 'pollNodeResponseDD',
lines:false,
rootVisible:false
});


root = new Ext.tree.AsyncTreeNode({
text: 'Root is hidden',
draggable:false,
id:"treeRoot",
allowDrop:true,
children: responseDataNode,
type:"root"
});

MrKurt
12 Apr 2007, 10:04 AM
Ah, that's exactly what I was missing, sweet.

Even overriding processResponse doesn't look terribly difficult, actually.

simeon
12 Apr 2007, 10:05 AM
note that I just edited my code sample. "responseDataNode" needs to be an array.