Jqueryztree implements tree search function _ jquery

Source: Internet
Author: User
This article mainly introduces the Tree search function of jqueryztree. zTree is a set of Tree plug-ins that can complete most common functions using JQuery's core code, if you are interested in ztree, you can refer to the examples in this article to share the jquery ztree implementation tree search function for your reference. The specific content is as follows:

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   } }; 

Here we need to add a property: view: {fontCss: getFontCss}
Here, getFontCss writes a method for itself:

function getFontCss(treeId, treeNode) {  return (!!treeNode.highlight) ? {color:"#A60000", "font-weight":"bold"} : {color:"#333", "font-weight":"normal"}; } 

In this way, the color changing function can be realized;
Next, add a search input box above the self-written display tree:

Filter by name:

    Here we can see that the changeColor method is called:

    // Use the search data and highlight function. Two steps are required. // 1. add fontCss: getFontCss settings to the setting view settings of the tree. // 2. add a text box at the top of the ztree container and add an onkeyup event. This event calls the fixed method changeColor (id, key, value) // id refers to the id of the ztree container, which is generally ul, key refers to which attribute of the data of the ztree node is used as the filter condition, and value refers to the filter condition. The filter is a fuzzy filter 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
     
      

    Is the ztree function for retrieval;
    In this way, you can implement the search function.

    The above is the information about how ztree is analyzed to implement the tree search function. We hope to learn from you.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.