dhtmlxtree笔记

1,基本写法
<body>
    <link rel="STYLESHEET" type="text/css" href="css/dhtmlxtree.css">
    <script  src="js/dhtmlxcommon.js"></script>
    <script  src="js/dhtmlxtree.js"></script>
    <div id="treeboxbox_tree"></div>
    <script type="text/javascript">
  tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
  tree.attachEvent("onClick",onNodeSelect);
  tree.setImagePath("images/tree/");
  tree.setXMLAutoLoading("dept.do?action=folder_treeview");//逐级展开
  tree.loadXML("dept.do?action=folder_treeview&id=1");//初始化
  function onNodeSelect(nodeId){
      document.getElementById("parent_folder_id").value = nodeId;
  }
    </script>
</body>


2,初始化需要的xml,必须带item
<?xml version='1.0' encoding='utf-8'?>
<tree id="0">
<item nocheckbox="1" open="1" id="-1" select="0" text= "公司" >
<item  open="1" child="1"  text= "财务部" id= "1"></item>
<item  open="1" child="0"  text= "技术部" id= "2"></item>
<item  open="1" child="0"  text= "人事部" id= "4"></item>
</item>
</tree>
注意<tree>里的id的值必须和 dhtmlXTreeObject的第4个参数的值保持一致,否则会报错:
Error type: DataStructure
Description: XML reffers to not existing parent

3,逐级展开的xml
<?xml version="1.0" encoding="utf-8"?><tree id="3">
<item  open="1" text= "甲部门" id= "5" ></item>
<item  open="1" text= "乙部门" id= "6" ></item>
</tree>

4,child属性表示是否有子级

你可能感兴趣的:(dhtmlxtree笔记)