javascript - 如何使用 TreeListFilter 列出与输入搜索文本关联的子元素?

标签 javascript html

使用 http://wiki.aiwsolutions.net/2014/03/12/tree-list-filter-plugin/ 中的 TreeListFilter.js

我尝试修改代码以使匹配的输入搜索文本的子元素(ul/li)也被列出,但它不起作用。尽管如此,显示仍会停止在无序列表中的匹配级别。

非常感谢任何帮助。

最佳答案

我认为您需要进行的关键更改是首先搜索当前节点的直接文本,然后确保将此结果传达给子节点。

// Search own text only (not including children)
var text = liObject.clone().children().remove().end().text();

// Match or parent is visible
display = text.toLowerCase().indexOf(filterValue) >= 0 || parentDisplay;

if (liObject.children().length > 0) {
    for (var j = 0; j < liObject.children().length; j++) {
        // Ask child to search self and let them know parents display result
        var subDisplay = filterList(jQuery(liObject.children()[j]), filterValue, display);

        // If child is visible at this stage, make parent visible, if 
        // parent visible, this will already be true
        display = display || subDisplay;
    }
}       

完整示例在这里:https://jsfiddle.net/on2u2584/1/

关于javascript - 如何使用 TreeListFilter 列出与输入搜索文本关联的子元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29823103/

相关文章:

javascript - 循环遍历数组并设置变量

javascript - Behat 测试验证消息

javascript - 使用 jquery 查找下拉选择值的总数

javascript - 如何在没有 jQuery 的情况下按顺序向元素添加类

html - 修复内容左右两侧的空隙

html - 如何在div内放入表格

html - 在 Powershell 中解析 html 实体

javascript - 根据另一个数组过滤一个数组

javascript 函数中的 C# 参数

javascript - 添加超时会破坏一切