1.引入各种包,在官网下载Ztree
2.action中配置书的各节点信息
/**
* 获取所有指标,构建指标树
* @return
*/
public String initIndexTree(){
System.out.println("树开始");
String Pid = "0";
List
firstIndexId = menuList.get(0).getEconIndexId();
firstTBIndextId = menuList.get(0).getEconIndexId();
System.out.println(firstIndexId+"在树里");
indexTree="[{ id:\"\", pId:\"-1\", name:\"指标体系\",value:\"-1\", open:true}";
for(int i=0;i
if(sEI.getEconIndexId().length()==5)
Pid = "";
else
Pid =sEI.getEconIndexId().substring(0,sEI.getEconIndexId().length()-5);
if(sEI.getEconIndexId().length()==5){
indexTree+=","+"{id:\""+sEI.getEconIndexId()+"\", pId:\""+Pid+"\", name:\""+sEI.getEconIndexName()+"\",value:\""+sEI.getEconIndexId()+"\", open:true}";
}else if(sEI.getEconIndexId().substring(0, 5).matches(firstIndexId)&&sEI.getEconIndexId().length()<=10){
indexTree+=","+"{id:\""+sEI.getEconIndexId()+"\", pId:\""+Pid+"\", name:\""+sEI.getEconIndexName()+"\",value:\""+sEI.getEconIndexId()+"\", open:true}";
}else{
indexTree+=","+"{id:\""+sEI.getEconIndexId()+"\", pId:\""+Pid+"\", name:\""+sEI.getEconIndexName()+"\",value:\""+sEI.getEconIndexId()+"\", open:false}";
}
}
indexTree+="]";
System.out.println(indexTree);
return SUCCESS;
}
3、jsp中用javascript调用
}
//初始化树
function initEmptyZTree() {
$.ajax( {
url : "${ctx}/Ajax/business/econIndexSys/SysEconIndexAjax/initIndexTree.do?randomnumber="+Math.random(),
type : "get",
dataType : "json",
cache: false,
success : innitTwoZtree
});
}
//点击指标名字,在右边出现他的下级指标列表
function zTreeOnClick(event,treeId,treeNode){
var id = treeNode.id;
$.ajax( {
url : "${ctx}/Ajax/business/econIndexSys/SysEconIndexAjax/getNextleavelIndex.do?indexId="+id,
type : "get",
dataType : "json",
cache: false,
success : initRightTable
});
}
function initZtree(json) {
var data = (json.indexTree);
//alert(data);
var zNodes = eval("(" + data + ")");
zTreeObj = $.fn.zTree.init($('#zTreePerm'), setting, zNodes); //这里制定树显示的位置
py = $("#py").attr("checked")? "p":"p",
sy = $("#sy").attr("checked")? "s":"s",
pn = $("#pn").attr("checked")? "p":"p",
sn = $("#sn").attr("checked")? "s":"s",
type = { "Y":py + sy, "N":pn + sn};
zTreeObj.setting.check.chkboxType = type;
}
var zTreeObj; //这里进行树的设置,详细可参照官网的中文配置
var setting = {
check : {
enable : false
},
data : {
simpleData : {
enable : true
}
},
callback: {
onClick: zTreeOnClick
}
};
4.页面html代码