Board Logo

using reset_state in Tigra Tree Pro
bill.smith - 8/5/2005 at 02:23 PM

Hi. I have Tigra Tree Pro. Works great at displaying a tree.

I am trying to use the reset_state function, and I don't have a clue how to do it. My page has:

<script language="JavaScript" src="tree/tree.js"></script>
<script language="JavaScript" src="tree/tree_tpl.js"></script>
<script language="JavaScript">var TREE_ITEMS = [ blah, blah, blah ]</script>

<script language="JavaScript">
new tree (TREE_ITEMS, TREE_TPL);
</script>

How and where do I use the reset_state function?


rock - 8/5/2005 at 02:32 PM

It depends on what are you tring to do.
Following example kills all saved tree states and opens all roots items after reload:
var tree_tpl = {

....

'beforeInit':'killTreeStates',
'afterInit':'opentoDepth'
// make sure there is no comma after the last key-value pair
};

function killTreeStates(o_tree){
o_tree.o_root.reset_state(); //reset open/close/selected states of the tree
return true;
}

function opentoDepth(o_item){
if(o_item.a_children && o_item.n_depth<0) //n_depth<0 - open roots; n_depth<1 - open roots and first level nodes, etc.
for(var i=0; i<o_item.a_children.length; i++){
o_item.a_children[i].open() // open item
opentoDepth(o_item.a_children[i]) //recursive call
}
}


bill.smith - 8/5/2005 at 02:45 PM

Hi.

Thanks for the quick response. I would like to reset the tree state to the default some of the time. I really don't understand your answer at all.

What I would like to do is something like:

<script language="JavaScript" src="tree/tree.js"></script>
<script language="JavaScript" src="tree/tree_tpl.js"></script>
<script language="JavaScript">var TREE_ITEMS = [ blah, blah, blah ]</script>

<script language="JavaScript">
new tree (TREE_ITEMS, TREE_TPL);
if ( a > b ) {
<reset the tree state to the default>
}
</script>


rock - 8/5/2005 at 03:32 PM

Ok, try to modify your tree_tpl.js file like:
var tree_tpl = {

....

'beforeInit':'killTreeStates',
'afterInit':'opentoDepth'
// make sure there is no comma after the last key-value pair
};

function killTreeStates(o_tree){
if(a > b) {//need reset_state
o_tree.o_root.reset_state(); //reset open/close/selected states of the tree
return true;
}
}


function opentoDepth(o_item){
if(a > b) {//need reset_state
if(o_item.a_children && o_item.n_depth<1) //n_depth<0 - open roots; n_depth<1 - open roots and first level nodes, etc.
for(var i=0; i<o_item.a_children.length; i++){
o_item.a_children[i].open() // open item
opentoDepth(o_item.a_children[i]) //recursive call
}
}
}
}


bill.smith - 8/5/2005 at 03:45 PM

Thanks Rock!

That is what I was looking for.


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