日期:2014-05-17  浏览次数:20846 次

dhtmlxTree 使用示例

http://dhtmlx.com 包含目录树、菜单、工具条等很多js控件,功能十分强大。
现将dhtmlxTree 使用样例记录如下(包括目录树、上下文菜单)
1
、所需js文件

dhtmlxcommon.js
dhtmlxtree.js
dhtmlxtree_json.js

//
菜单控件所需的js
dhtmlxprotobar.js
dhtmlxmenubar.js
dhtmlxmenubar.js

2sample.html代码:

<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>
无标题文档</title>
<script?src="./dhtmlxcommon.js"></script>
<script?src="./dhtmlxtree.js"></script>
<script?language="JavaScript"?src="./extend/dhtmlxtree_json.js"></script>
<script?language="JavaScript"?src="./dhtmlxprotobar.js"></script>
<script?language="JavaScript"?src="./dhtmlxmenubar.js"></script>
<script?language="JavaScript"?src="./dhtmlxmenubar_cp.js"></script>
<link?rel="STYLESHEET"?type="text/css"?href="./dhtmlxtree.css">
<link?rel="STYLESHEET"?type="text/css"?href="./context.css">
<link?rel="STYLESHEET"?type="text/css"?href="./dhtmlxmenu.css">
</head>
<body>
<div?id="treeBox"?style="width:200;height:200"></div>
<script>
??
//init?menu?
??aMenu=new?dhtmlXContextMenuObject('120',0,"images/");
??aMenu.menu.loadXML("./_context.xml");
??aMenu.setContextMenuHandler(onMenuClick);
??
??tree=
new?dhtmlXTreeObject('treeBox',"100%","100%",0);
??tree.setImagePath("images/");
??tree.enableCheckBoxes(
true);
??tree.enableDragAndDrop(
true);
??tree.enableContextMenu(aMenu);?
//link?context?menu?to?tree
??tree.loadCSV("./data.txt");//for?loading?from?file
??
??
function?onMenuClick(id,s){?alert("Menu?item?"+id+"?was?clicked"+s);?}
</script>
</body>
</html>

3、数据文件data.txt

1,0,node?1?
2,1,node?1.1?
3,2,node?1.1.1?
4,0,node?2
bd2f46a212ffae3b011305afd5eb0108,4,node?2.1
6,1,node?1.2

4、菜单文件_context.xml

<?xml?version='1.0'??>
<menu?absolutePosition="auto"?mode="popup"?m