function close_ztree(treeId){
var treeObj = $.fn.zTree.getZTreeObj(treeId);
var nodes = treeObj.transformToArray(treeObj.getNodes());
var nodeLength = nodes.length;
for (var i = 0; i < nodeLength; i++) {
if (nodes[i].id == '0') {
//根节点:展开 treeObj.expandNode(nodes[i],false);
} else {
//非根节点:收起 treeObj.expandNode(nodes[i],false);
}
}
}
function search_ztree(treeId,searchConditionId){
searchByFlag_ztree(treeId,searchConditionId,"");
}
function searchByFlag_ztree(treeId,flag){
//<1>.搜索条件 var searchCondition = $('#' + searchConditionId).val();
//<2>.得到模糊匹配搜索条件的节点数组集合 var highlightNodes = new Array();
if (searchCondition != "") {
var treeObj = $.fn.zTree.getZTreeObj(treeId);
highlightNodes = treeObj.getNodesByParamFuzzy("name",searchCondition,null);
}
//<3>.高亮显示并展示【指定节点s】 highlightAndExpand_ztree(treeId,highlightNodes,flag);
}
function highlightAndExpand_ztree(treeId,flag){
var treeObj = $.fn.zTree.getZTreeObj(treeId);
//<1>. 先把全部节点更新为普通样式 var treeNodes = treeObj.transformToArray(treeObj.getNodes());
for (var i = 0; i < treeNodes.length; i++) {
treeNodes[i].highlight = false;
treeObj.updateNode(treeNodes[i]);
}
//<2>.收起树,只展开根节点下的一级节点 close_ztree(treeId);
//<3>.把指定节点的样式更新为高亮显示,并展开 if (highlightNodes != null) {
for (var i = 0; i < highlightNodes.length; i++) {
if (flag != null && flag != "") {
if (highlightNodes[i].flag == flag) {
//高亮显示节点,并展开 highlightNodes[i].highlight = true;
treeObj.updateNode(highlightNodes[i]);
//高亮显示节点的父节点的父节点....直到根节点,并展示 var parentNode = highlightNodes[i].getParentNode();
var parentNodes = getParentNodes_ztree(treeId,parentNode);
treeObj.expandNode(parentNodes,true);
treeObj.expandNode(parentNode,true);
}
} else {
//高亮显示节点,并展开 highlightNodes[i].highlight = true;
treeObj.updateNode(highlightNodes[i]);
//高亮显示节点的父节点的父节点....直到根节点,并展示 var parentNode = highlightNodes[i].getParentNode();
var parentNodes = getParentNodes_ztree(treeId,parentNode);
treeObj.expandNode(parentNodes,true);
treeObj.expandNode(parentNode,true);
}
}
}
}
function getParentNodes_ztree(treeId,node){
if (node != null) {
var treeObj = $.fn.zTree.getZTreeObj(treeId);
var parentNode = node.getParentNode();
return getParentNodes_ztree(treeId,parentNode);
} else {
return node;
}
}