dhtmlx tree的使用方式

步骤:

1.导入dhtmlx的相关js文件与css文件

2.进行JS调用

//定义树
var tree;
function loadTree(){
	$('#doctree_box').html('');
	//创建一棵树
	//参数含义 1.对应的树div id 2,3对应长宽 4对应树根节点ID
    tree=new dhtmlXTreeObject("doctree_box","100%","100%",0);
    //设置样式
    tree.setSkin('dhx_skyblue');
    //设置背景图片路径
    tree.setImagePath( ctx+"/images/dhtmlx/csh_yellowbooks/");
    //点击树时出发的函数
    tree.setOnClickHandler(
        function(id){openPathDocs(id); }
    );
    //请求url
    var url=ipAddress+ctx+"/sale/orderPoolManager.do?flag=tree";
    
    tree.setXMLAutoLoading(url);
    //实现树的展示
    tree.loadXML(url);
   
 }

点击数的函数:

/* open path funtion */
function openPathDocs(id){
    if (tree.getUserData(id, "centerId") != null ){
        alert(tree.getUserData(id, "centerId"));
        return;
    }else{
    	alert('获取centerId值失败!');
    }
}

3.进行树结构的定义,可以采用xml报文或者dom4j生成xml

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<?xml version="1.0" encoding="UTF-8"?>
<tree id='0'>
	<item id='node_1' open='1' text='XXX查询' child='1' im0='folder.gif' im1='folderopen2.gif'
		im2="folder.gif">
		
		<!-- 此处为动态写入 START -->
		<item id='center_01' text='待解决(20)'  im0='page.gif' im1='page.gif' im2='page.gif'>
		    <userdata name="poolStatus">wait</userdata>
		</item>
		
		<item id='center_02' text='处理中(1)' im0='page.gif' im1='page.gif' im2='page.gif'>
			    <userdata name="poolStatus">process</userdata>
		</item>
		
	    <item id='center_03' text='已处理' im0='page.gif' im1='page.gif' im2='page.gif'>
			    <userdata name="poolStatus">done</userdata>
		</item>
		
		<!-- 此处为动态写入 END -->
	</item>
</tree>



你可能感兴趣的:(dhtmlx tree的使用方式)