Board Logo

menu control from outside code
dushik - 9/8/2003 at 06:58 AM

How can I control menu items from outside? for example I want to open node by javascript, not by clicking on it. I've tried to do it by placing the code

for (var i = 0; i < this.a_children.length; i++) {
this.a_children[i].open();
}

in the end of tree_item() function, I thought it would result 'expand all', but it didn't work as expected.


Ulukai - 9/24/2003 at 10:10 AM

Well its ages ago that I used and modified the tree, but I?m sure I can give you some hints.
If you want to open all of the nodes when creating the tree, you will have to add a function. That?s because the init function doesn?t actually initialize the item at the moment when the function returns but returns a string to be rendered by the caller (after rendering the string, the items will be accessable).
You have to create a function recursive_open, that goes through all children and opens them via recursive_open.

this is the body of the function in pseudocode. That should work.

this.open();
for-all-children
thechild.recursive_open(true);

To control the tree via extern controls, you have to know the id of the tree-nodes, which is not that simple, because they are incremented when constructing the tree.
You could write a search-function which returns IDs for node-titles (either you must ensure that node-titles are unique or you have to return an array).
With this function you may control the tree. Then you will have to add another recursive_open-function which goes the other way, calling an item which may be hidden at the moment must force the tree to open all parents of this item.

The body of this function could look like this:
recursive_open2(){
parent.recursive_open2();
this.open(true);
}

I guess the pseudo-code of the functions is far too simple, you will have to experiment with it. But perhaps those hints could help you.
Have fun

Ulukai


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/