下面是实现:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="../js/jquery-latest.js"></script>
<script src="../js/select.js"></script>
<link rel="StyleSheet" href="/sch/js/dtree.css" type="text/css" />
<script type="text/javascript" src="/sch/js/dtree.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//获取顶级部门
d = new dTree('d');
d.add(0,-1,'系统');
$.ajaxSetup({cache:false});
$.getJSON("/sch/GetJsonServlet?Method=getTopOrgJson",function call(data){
var org=data.orgList;
alert(org.length);
for(var i=0;i<org.length;i++){
//id, pid, name, url, title, target, icon, iconOpen, open
d.add(org[i].ID,0,org[i].description,"javascript:addNextOrg('"+org[i].ID+"');",'测试节点');
}
$("#showDtree").html(d.toString());
});
});
//获取下级部门
function addNextOrg(ID){
alert("hello");
$.getJSON("/sch/GetJsonServlet?Method=getNextOrgJson&ID="+ID,function call(data){
var org=data.orgList;
if(org.length!=0){
for(var i=0;i<org.length;i++){
d.add(org[i].ID,ID,org[i].description,"javascript:addNextOrg('"+org[i].ID+"');",'测试节点');
}
$("#showDtree").html(d.toString());
}
});
}
function showformDiv(id){
$('.formDiv').hide();
$(id).show();
}
function buildOrg(){
var str=$("#buildOrg").serialize();
alert(str);
$.getJSON("/simple/DynajetServlet?Method=buildOrg&"+str,function call(data){
var result=data.result;
// alert("hello");
$("#result").text(result);
});
}
function orgChange(){
$.ajaxSetup({cache:false});
var orgId=$("#orgList").val();
alert(orgId);
$.getJSON("/simple/SalesServlet?Method=getRoleJson&orgId="+orgId,function call(data){
var continents =data.roleList;
for(var i=0;i<continents.length;i++){
$("#roleList").append('<option value='+continents[i].roleId+'>'+continents[i].description+'</option>');
}
});
}
</script>
<body>
<div id="showDtree">
</div>
</body>
</html>