ztree实现下拉树展示
var Setting = {
view: {
dblClickExpand: false
},
data: {
simpleData: {
enable: true
}
},
callback: {
onClick: orgOnClick
}
};
/*
* 设备类型下拉树的点击事件
*/
function orgOnClick(e, treeId, treeNode) {
var zTree = $.fn.zTree.getZTreeObj("tree");
nodes = zTree.getSelectedNodes();
$("#orgId").val(nodes[0].id);
$("#orgName").val(nodes[0].name);
}
/*
* 初始化设备类型
*
function initDeviceType(){
$.ajax({
url:urlDomain+'/Dvice-queryDeviceTypeTree',
type:'POST',
data:{
idevicetypeid:-1,
scompanycode:companyCode
},
async:false,
success:function(msg){
var obj = eval("("+msg+")");
var orgNodes = [];
getDevTypeObj(obj,orgNodes);
$.fn.zTree.init($("#tree"), Setting, orgNodes);
}
});
}
/*
* 展示设备类型SelectTree
*/
function showDevTypeTree(){
$.ajax({
url : path+"/OrganizeController/getOrgTree.do",
type:'POST',
async:false,
success:function(msg){
var obj = eval("("+msg+")");
var orgNodes = [];
getDevTypeObj(obj,orgNodes);
$.fn.zTree.init($("#tree"), Setting, orgNodes);
var deptObj = $("#orgName");
var deptOffset = $("#orgName").offset();
$("#devTree").css({top:deptObj.outerHeight()+"px"}).slideDown("fast");
$("#tree").css({width:deptObj.outerWidth() - 12 + "px"});
var zTree = $.fn.zTree.getZTreeObj("tree");
var node = zTree.getNodeByParam("id", $('#orgId').val(), null)
zTree.selectNode(node);
$("body").bind("mousedown", onBodyDownByDevType);
}
});
}
/**
* 设备类型
*
* @param {} dataObj
* @param {} treeNodes
*/
function getDevTypeObj(dataObj,treeNodes){
for (var i = 0; i < dataObj.length; i++)
{
treeNodes.push({id:dataObj[i].id,pId:dataObj[i].pId,name:dataObj[i].name});
loadChild(dataObj[i],treeNodes);
}
}
/**
* 查找子节点
*
* @param {} dataObj
* @param {} treeNodes
*/
function loadChild(dataObj,treeNodes){
var childObj = dataObj.children;
if(childObj != undefined)
{
for(var j = 0; j < childObj.length; j++)
{
treeNodes.push({id:childObj[j].id,pId:childObj[j].pId,name:childObj[j].name});
loadChild(childObj[j],treeNodes);
}
}
}
/*
* Body鼠标按下事件回调函数
*/
function onBodyDownByDevType(event) {
if(event.target.id.indexOf('switch') == -1){
hideDeviceTypeMenu();
}
}
/*
* 隐藏设备类型Tree
*/
function hideDeviceTypeMenu() {
$("#devTree").fadeOut("fast");
$("body").unbind("mousedown", onBodyDownByDevType);
}