View Full Version : Passing Tree Node Text in TreeLoader

22 Feb 2008, 1:45 PM
I would like to pass the text of the tree node back in the parameters of the Ajax call for children of a node.

Looking at Firebug I see that EXT by default sends the Node ID to the server, but since these IDs are created client side, they are unknown to the database.

I have tried to set my own IDs from my data but often times the folder has a single quote e.g. "John's Stuff" and this will cause problems in the Tree object even when converted on the server using the htmlspecialchars() function. The organization of the data isn't mine, so I don't have control on the tables.

I noticed the TreeLoader class can be configured to pass parameters, but I'm trying to figure out how to set the baseParams so it will pass the expanded node's text property.

Thanks for any assistance.

23 Feb 2008, 6:40 AM
Well for all the reading and searching I did, there was the answer right in front of me in the API documentation 8-|.

A server request is sent, and child nodes are loaded only when a node is expanded. The loading node's id is passed to the server under the parameter name "node" to enable the server to produce the correct child nodes.

To pass extra parameters, an event handler may be attached to the "beforeload" event, and the parameters specified in the TreeLoader's baseParams property:

myTreeLoader.on("beforeload", function(treeLoader, node) {
this.baseParams.category = node.attributes.category;
}, this); This would pass an HTTP parameter called "category" to the server containing the value of the Node's "category" attribute.

I did however have a small problem with this construct, and had to change it slightly to get it to work.

myTreeLoader.on("beforeload", function(treeLoader, node) {
treeLoader.baseParams.category = node.attributes.category;
}, this);