Ztree树节点模糊搜索(兼容ie和firefox)
通过获取输入框值,模糊查找树节点。var count=0;
var lastName;
function searchTree(){
if(count==0){
lastName=document.getElementById("id").value;
}
if(lastName!=document.getElementById("id").value){
count=0;
lastName=document.getElementById("id").value;
}
var treeObj = $.fn.zTree.getZTreeObj("tree");
//通过名称模糊搜索,也可通过Id查找
var nodes = treeObj.transformToArray(treeObj.getNodesByParamFuzzy("name", lastName, null));
for(i = count; i < nodes.length; i++) {
count++;
if(count>=nodes.length){
count=0;
}
if(nodes.name.indexOf(lastName)!=-1){
treeObj.selectNode(nodes);
if(nodes.icon=="xx.png"){
parent.mainFrame.location.href = "xx.jsp;
}else if(nodes.icon=="xx.png"){
parent.mainFrame.location.href = "xx.jsp";
}else if(nodes.icon=="xx.png"){
parent.mainFrame.location.href = "xx.jsp";
}
//实现自动打开
//treeObj.expandNode(nodes, false,false , false);
return;
}
}
}
页:
[1]