【问题标题】:display error to user if a search text not found如果未找到搜索文本,则向用户显示错误
【发布时间】:2013-03-06 18:58:20
【问题描述】:

我有这个绑定到 jstree 并搜索树的 jquery 脚本,如果找到会突出显示三个节点。哪个有效。但是,如果未找到搜索测试,我想向用户提醒消息。有什么想法我会怎么做?

Javascript:

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

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

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

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

    });

     document.getElementById("search_field").value='';
     }); 
    }

html:

<fieldset id="search">

    <input type="text" name="search_field" id="search_field" value="" />
    <button id="search_tree" onclick="myFunction()"> Search</button>

</fieldset>

【问题讨论】:

    标签: jquery jstree


    【解决方案1】:

    您可以从下面的代码中得到一个想法。如果您需要任何进一步的帮助,请提供有效的 jsfiddle 示例,我将修改代码以使用您的代码。

    $("div#jstree").bind("search.jstree", function (e, data) {
        //document.getElementById("results").innerHTML="Found " + data.rslt.nodes.length + " nodes matching '" + data.rslt.str + "'.";
       if (data.rslt.nodes.length == 0){
        alert("No search results found");
       }
    });
    

    【讨论】:

    • 由于某种原因我无法创建 jsfiddle。我的原始代码在帖子中。我尝试过这样的事情:$("#tree").jstree("search",value)。 function (e, data) { if (data.rslt.nodes.length == 0){ alert("未找到搜索结果"); } 虽然游戏我一个错误
    • 有什么想法可以解决这个问题吗?
    • 从 jsTree 3.0.0-beta8 开始,这是:if (data.res.length == 0)
    猜你喜欢
    • 2015-07-10
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多