jsTree 仅在“文件”中搜索或“文件夹”标题

发布于 2024-12-25 06:01:01 字数 74 浏览 6 评论 0 原文

我有一个 2 层 jsTree。第一层是“文件夹”。第二层是“文件”。是否可以仅在文件标题或文件夹标题中搜索?不在整个jstree中。

I have a 2-layer jsTree. First layer is "folders". Second layer is "files". Is it possible to search only in file titles or in folder titles? Not in the whole jstree.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风挽心 2025-01-01 06:01:01

看起来您无法使用标准 jsTree 搜索插件 来完成此操作,

好消息是您可以< a href="https://github.com/vakata/jstree/issues/10" rel="nofollow">编写自己的搜索功能。这是摘录。它演示了如何使用自定义函数来搜索由空格分隔的多个单词:

我需要搜索由空格分隔的多个单词,所以我给出
你我的功能是添加到搜索插件(当前搜索引擎
插件仅搜索一个单词)。

<前><代码>/*
* jsTree搜索插件
* 在树上启用同步和异步搜索
* 不适用于 JSON 渐进式渲染
*/
(函数($){

$.expr[':'].jstree_contains_multi = 函数(a,i,m){

var 单词, 单词 = [];
var searchFor = m[3].toLowerCase().replace(/^\s+/g,'').replace(/\s+$/g,'');
if(searchFor.indexOf(' ') >= 0) {
单词 = searchFor.split(' ');
}
别的 {
单词=[搜索];
}
for (var i=0; i = 0) {
返回真;
}
}
返回假;

};

$.expr[':'].jstree_contains = 函数(a,i,m){

return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase())>=0;

};

It doesn't look like you can do it using standard jsTree search plugin

Good news that you can write your own search function. Here is an excerpt. It shows demonstrates using a custom function to search for multiple words separated by spaces:

I needed to search for multiple words separated by spaces so I give
you my function to add to search plugin (currently the search engine
plugin only search for one word).

/*
 * jsTree search plugin
 * Enables both sync and async search on the tree
 * DOES NOT WORK WITH JSON PROGRESSIVE RENDER
 */
(function ($) {

    $.expr[':'].jstree_contains_multi = function(a,i,m){

        var word, words = [];
        var searchFor = m[3].toLowerCase().replace(/^\s+/g,'').replace(/\s+$/g,'');
        if(searchFor.indexOf(' ') >= 0) {
            words = searchFor.split(' ');
        }
        else {
            words = [searchFor];
        }
        for (var i=0; i < words.length; i++) {
            word = words[i];
            if((a.textContent || a.innerText || "").toLowerCase().indexOf(word) >= 0) {
                return true;
            }
        }
        return false;

    };

    $.expr[':'].jstree_contains = function(a,i,m){

        return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase())>=0;

    };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文