Posted on 2009-01-15 23:58
leekiang 閱讀(1647)
評論(0) 編輯 收藏 所屬分類:
web開發
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: XMLrefferstonotexistingparent
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屬性表示是否有子級