jquery - 使用 jquery javascript 搜索 jstree 节点

标签 jquery jstree

我正在使用 jstree 插件来构建我的树。我的网页中有一个搜索框,我需要用户能够在其中搜索 jstree 节点。

<fieldset id="search">

    <input type="text" name="search_field" id="search_field" value="" />
    <button id="search_tree">Search</button>

  </fieldset>

当点击搜索时,jstree 节点应该展开,如果找到,节点应该突出显示。如果未找到,则应向用户显示错误,如“未找到”。我的代码用于展开下面的所有节点。有没有一种简单的方法来搜索jstree中的所有节点?

<script type="text/javascript"> 
     $(document).ready(function(){

         $("#search_tree").click(function () {  
    var value=document.getElementById("search_field").value; 
         $("#tree").jstree("search",value);  

     });  

     $("#tree").jstree({  



         "xml_data" : {  

             "ajax" : {  

                 "url" : "jstree.xml" 

             },  

             "xsl" : "nest"


         },  
         "themes" : {  

             "theme" : "classic",  

            "dots" : true,  

             "icons" : true 

         },  

             "search" : {  

                 "case_insensitive" : true,  

                 "ajax" : {  

                     "url" : "jstree.xml" 

                 }  

             },  
              "plugins" : ["themes", "xml_data", "ui","types", "search"] 

         });  



 }); 

</script>

我收到此错误:

Instances[...] 为 null 或不是对象。这是一个 jstree 错误。有什么想法吗?

最佳答案

我已将这段代码添加到我的函数中:

"search" : {  

                 "case_insensitive" : true,  

                 "ajax" : {  

                     "url" : "jstree.xml" 

                 }  

             },  
              "plugins" : ["themes", "xml_data", "ui","types", "search"] 

创建了此函数并与我的点击按钮相关联:

function myFunction()
{
$(document).ready(function(){

var value=document.getElementById("search_field").value; 

    $("#search_tree").click(function () { 

        $("#tree").jstree("search",value) 
 }); 

 }); 
}

关于jquery - 使用 jquery javascript 搜索 jstree 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14959988/

相关文章:

javascript - 如何使用 jQuery 获取图像 ID?

javascript - 需要像工具提示一样的 html 弹出窗口帮助

javascript - 与可拖动插件一起使用时,Tablesorter 会出现问题。

php - 无法在 ajax 调用中发布绝对文件路径 - 无论我做什么它都会删除反斜杠

javascript - 动态排列三 Angular 形中的元素?

javascript - 添加元素后触发 JavaScript 代码

jquery - jsTree不创建特定类型的节点

jstree - 如何使用单个属性在 jsTree 节点中存储多条数据?

javascript - 以编程方式将子节点添加到 jstree

javascript - 单击箭头或其他图标以伸展树(Splay Tree)的分支时会触发什么事件?