PDA

View Full Version : TreePanel more parameters



orhant
21 Jan 2007, 2:58 PM
Hi all;

I have one question about TreePanel. I have Json output like below.


[{"text":"KONTROLLER","url":"denem.php","target":"iframe","id":"1","cls":"folder"},{"text":"M\u0130M","url":"show.php","target":"tab",id":"9","cls":"folder"}]

Tree code like:


var tree = new Tree.TreePanel(viewEl, {
animate:true,
loader: new Tree.TreeLoader({dataUrl:'get-nodes3.php'}),
enableDD:true,
containerScroll: true,
enableDD:true,
containerScroll: true,
ddGroup: 'organizerDD',
rootVisible:true,expanded:false
});

tree.on('click', this.showFullPost,this);

And on clik function

showFullPost : function(node){
alert(node.id); //works
alerd(node.url) // nor work . Actually does not work.

}

How can I pass json output url and target parameters to showFullPost function.

Thanks everybody.

tryanDLS
21 Jan 2007, 3:03 PM
You should be able to pass additional parms via createDelegate()



tree.on('click', this.showFullPost.createDelegate(this, [args], true))


Look at the doc to see more.

orhant
21 Jan 2007, 3:09 PM
Thanks tryanDls .

I know that. but I don't know , how can I get extra parameters from TreeLoader({dataUrl:'get-nodes3.php'}) .I get some extra url and target parameters from nodes3.php.

Thanks again.

tryanDLS
21 Jan 2007, 3:32 PM
If you want to pass additional parms to your php page, it looks like you can add a baseParams object to your config when set up your TreeLoader.

orhant
21 Jan 2007, 3:48 PM
I thing I did not ask problem clearly.I want to get argument that returned from


loader: new Tree.TreeLoader({dataUrl:'get-nodes3.php'}), .

Php output below arguments and tree of them used for createnode two of themn used in my function;


[{"text":"KONTROLLER","url":"denem.php","target":"iframe","id":"1","cls":"folder"},{"text":"M\u0130M","url":"show.php","target":"tab",id":"9","cls":"folder"}]

Text ->used for createNode;
id ->used for createNode;
cls ->used for createNode;
url -> i added php output and I need this in my function but i dont know how can i get it.
target -> i added php output and I need this in my function but i dont know how can i get it.

jack.slocum
21 Jan 2007, 5:53 PM
Check out this thread:

http://www.yui-ext.com/forum/viewtopic.php?t=2237

Then click on the link, and go to Ext.tree.TreeNode. The very first item on the list is:

attributes
public Object attributes
The attributes supplied for the node. You can use this property to access any custom attributes you supplied.

mikegiddens
21 Jan 2007, 6:40 PM
Thanks jack for the new .40 documentation. I did a little test to see that it works with what ever I send it from my json data.



tree.on('nodedragover', function(e){
console.log(e.target.attributes);
}


I am now using this feature to mark my nodes with a nodeType field that I use so when I expand a folder I know which child list to render.

I was hoping that it is possible to overload the async request when it is called from load or expand (Not sure who calls the async request) to include "attributes" as extra post data.

jack.slocum
22 Jan 2007, 1:20 PM
The getParams(node) function on the TreeLoader was separated out just for this purpose. Here's an example of overriding it:


var loader = new Ext.tree.TreeLoader(...);
loader.getParams = function(node){
this.baseParams = {
nodeType: node.attributes.nodeType,
foo: node.attributes.foo,
... etc
};
return Ext.tree.TreeLoader.prototype.getParams.call(this, node);
};

You can also do it without overriding the function by using the beforeload event (this is probably better actually, the getParams was designed for subclasses)):


var loader = new Ext.tree.TreeLoader(...);
loader.on('beforeload', function(loader, node){
loader.baseParams = {
nodeType: node.attributes.nodeType,
foo: node.attributes.foo,
... etc
};
});

mikegiddens
22 Jan 2007, 3:17 PM
Thanks a bunch. Here is what I used to get it working based on the 2tree example.

I comment out the original baseParams on the constructor and add this on function.



tree.loader.on('beforeload', function(loader, node){
var nodeType = (node.attributes.nodeType) ? node.attributes.nodeType : "source";
loader.baseParams = {
lib: 'zones',
nodeType: nodeType // Custom var passed from get-nodes.php (json data)
};
});


Note that since I am putting this in the Tree:init function there is no nodeType variable in the attributes to start so you need to check to see if they exist then use a default if it is the first use or no var exist.

I hope this helps. Just passing on what I had to do to make someone elses life a bit easier.

orhant
24 Jan 2007, 12:28 PM
Thanks Jack. I solved using doc.


node.attributes.url

frankly
25 Jan 2007, 7:25 AM
Hi,
I can't figure out where you can add this. Can you tell me more?



var my_network = new Tree.TreePanel('my_network', {
animate:true,
loader: new Tree.TreeLoader({dataUrl:'get-nodes.php'}),
enableDD:true,
containerScroll: true,
lines:false
});

Do I have to name the Treeloader so it's accessible?
node.attributes refers to which Treeloader?

Thanks for the help :)

jack.slocum
25 Jan 2007, 8:47 AM
node.attributes is the json object passed into the TreeNode on construction. So it would be the json returned by the server when called by the loader.