dhtmlxtree使用
参考原文:http://flashdream8.iteye.com/blog/906486
http://zhaoshixing1228.blog.163.com/blog/static/282063082011128103829831/
引入必要的js和css
<link rel="stylesheet" type="text/css" href="<c:url value='/style/dhtmlxtree.css'/>">
<script type="text/javascript" src="<c:url value='/scripts/dhtmlxcommon.js'/>"></script>
<script type="text/javascript" src="<c:url value='/scripts/dhtmlxtree.js'/>"></script>
<table>
<tr>
<td valign="top">
<div id="treeboxbox_tree2" style="width:250; height:218;background-color:#f5f5f5;border :1px solid Silver;; overflow:auto;"></div>
</td>
</tr>
</table>
<script>
function treeClick(currentNodeId){
doLog("Item "+tree.getItemText(currentNodeId)+" was selected");
};
tree2=new dhtmlXTreeObject("treeboxbox_tree2","100%","100%",0);
tree2.setImagePath("/office/images/skyblue/");
tree2.enableCheckBoxes(1);
//允许三种状态的复选框(全选、不选、部分选中)
tree2.enableThreeStateCheckboxes(true);
//添加事件
tree2.attachEvent("onClick",treeClick);//点击事件
//允许单击事件
//tree2.setOnClickHandler(tonclick);
tree2.loadXML("<c:url value='/getTree.do'/>");
</script>
附件中为官方dhtmlxtree的示例。
tree的xml加载可以是使用servlet生成xml,也可以是使用action生成xml,我使用的是通过action生成xml。