Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted on Jul 28, 2009 04:22
open dhtmlx forum
dhtmlXTreeObject

Hi

I have the following, and this works... However when i change index in the combo box the next xml is appended to the end of the existing tree.

How would I tell this to replace the existing tree with the new one.

Thanks

Simon
<code>
<script language="javascript">
function cb_Value()
    {
    var fname;
    var w = document.cbmenu.mylist.selectedIndex;
    var selected_value = document.cbmenu.mylist.options[w].value;
    fname = w;
    //alert(selected_value)
    
    tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
    tree.setImagePath("js/imgs/csh_bluebooks/");
    tree.loadXML("js/"+selected_value);
    }
</script>
</code>
Answer posted by Alex (support) on Jul 28, 2009 05:03

Hello,

in order to reload tree you can use the following method:

tree.deleteChildItems(0);

tree.loadXML("js/"+selected_value);

Try to use it instead of 

tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0); 
tree.setImagePath("js/imgs/csh_bluebooks/"); 
tree.loadXML("js/"+selected_value);

Answer posted on Jul 28, 2009 05:09
Hi I just tried this

however this removes all child items and leaves the root.

The initial function is good but on change of selected index i would like to dispose the previous and load the new xml in its place?

Thanks

Simon
Answer posted on Jul 28, 2009 05:12
Hi I just tried this

however this removes all child items and leaves the root.

The initial function is good but on change of selected index i would like to dispose the previous and load the new xml in its place?

Thanks

Simon
Answer posted by Alex (support) on Jul 28, 2009 05:14

In this case you can use just (without removing previous items):

tree.loadXML("js/"+selected_value);

Answer posted on Jul 28, 2009 06:06
Hi Alex thanks for the help

I am not sure I understand "

In this case you can use just (without removing previous items):

tree.loadXML("js/"+selected_value);"

Is this not what I already have? I am very new at this, I load the tree all good. But when I change selected index I wish the tree to be rebuilt with the new items and not add to the existing tree as if called for the 1st time.


Simon

Answer posted by Alex (support) on Jul 28, 2009 06:25

Ok... 

tree.loadXML("js/"+selected_value); loads items from the xml. This method will add new items to the existent structure.

If you want to rebuild tree, you can call tree.deleteChildItems(0); before loadXML to delete previous structure.

If you want to initialize tree again,  you can call desctructor() and then tree initialization code:

tree.destructor(); 

tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0); 
tree.setImagePath("js/imgs/csh_bluebooks/"); 
tree.loadXML("js/"+selected_value);

Answer posted on Jul 28, 2009 06:29
Aha Superb, thanks that now works great.

Thank you for the effort in helping a newb.

Simon