I would like to be able to select an item in my tree after loading the tree data from xml.
Here is my code
var tree = new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
tree.setImagePath("dhtmlxTree/codebase/imgs/");
tree.loadXML('xml/navigation.xml', function() {
tree.openAllItems(0);
});
Later on
tree.selectItem(1);
selectItem should be called after xml loading.
var tree = new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
tree.setImagePath("dhtmlxTree/codebase/imgs/");
tree.loadXML('xml/navigation.xml', function() {
tree.openAllItems(0);
tree.selectItem(1);
});
selectItem takes item is as parameter. So, make sure that there is an item with id=“1”
Yes I understand that will work.
However, what if I want to do it later on.
For example, when a user selects an item in a dhtmlxCombo, it automatically selects the corresponding item in the tree.
If the item is loaded and not selected by selectItem method, please provide the sample to recreate the problem
Thanks Alexandra.
Don’t worry I got it working.
For the benefits of others:
combo.xml
<?xml version='1.0' encoding='iso-8859-1'?>
<complete>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
</complete>
tree.xml<?xml version='1.0' encoding='iso-8859-1'?>
<tree id="0">
<item text="Item 1" id="1"></item>
<item text="Item 2" id="2"></item>
<item text="Item 3" id="3"></item>
</tree>
HTML source
[code]
Tree selection
<link rel="stylesheet" type="text/css" href="/dhtmlxCombo/codebase/dhtmlxcombo.css">
<link rel="stylesheet" type="text/css" href="/dhtmlxTree/codebase/dhtmlxtree.css">
<script src="/dhtmlxCombo/codebase/dhtmlxcommon.js"></script>
<script src="/dhtmlxCombo/codebase/dhtmlxcombo.js"></script>
<script src="/dhtmlxTree/codebase/dhtmlxcommon.js"></script>
<script src="/dhtmlxTree/codebase/dhtmlxtree.js"></script>
[/code]