The example in this article shares the tree search function implemented by jquery ztree for your reference. The specific content is as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | var userZTree;
var userSetting={
check: {
enable: true,
chkStyle: "radio" ,
chkboxType : { "Y" : "" , "N" : "" },
radioType: "all"
},
data: {
simpleData: {
enable: true,
idKey : "id" ,
pIdKey : "pid"
}
},
callback:{
onClick : clickCheck
},
view :{
showIcon: false,
fontCss: getFontCss
}
};
|
Copy after login
Add an attribute here: view: {fontCss: getFontCss}
Here is a method of getFontCss written for myself:
1 2 3 | function getFontCss(treeId, treeNode) {
return (!!treeNode.highlight) ? {color: "#A60000" , "font-weight" : "bold" } : {color: "#333" , "font-weight" : "normal" };
}
|
Copy after login
In this way, the color changing function can be realized;
Next, you need to add a search input box above the display tree you wrote:
1 2 3 4 5 6 7 8 9 10 11 | <div id= "userDiv" class = "showParentDiv showDiv" style= "z-index:105;display: none;" >
<div class = "grayBg" >
<div class = "toolbar" >
<input type= "button" value= " <s:text name='button.submit'/> " onclick= "submitUser();" />
<input type= "button" value= " <s:text name='button.cancel'/> " onclick= "closeUserDiv();" />
<input type= "button" value= " 新建 " onclick= "toAddDiv();" />
</div>
</div>
<div style= "text-align:left;margin:5px;height: 15px;" >按名字过滤:<input type= "text" id= "dicKey" onkeyup= "changeColor('userTree','name',this.value)" /></div>
<ul id= "userTree" class = "ztree" style= "height:350px; overflow-y:scroll;" ></ul>
</div>
|
Copy after login
Here you can see that the changeColor method is called:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | function changeColor(id,key,value){
treeId = id;
updateNodes(false);
if (value != "" ){
var treeObj = $.fn.zTree.getZTreeObj(treeId);
nodeList = treeObj.getNodesByParamFuzzy(key, value);
if (nodeList && nodeList.length>0){
updateNodes(true);
}
}
}
function updateNodes(highlight) {
var treeObj = $.fn.zTree.getZTreeObj(treeId);
for ( var i=0; i<nodeList.length; i++) {
nodeList[i].highlight = highlight;
treeObj.updateNode(nodeList[i]);
}
}
treeObj.getNodesByParamFuzzy(key, value);
|
Copy after login
is the ztree function retrieved;
This is ok and the search function can be implemented.
The above is the relevant information about the ztree implementation of the tree search function analyzed for everyone. I hope it can help everyone learn.