0

我想为帐户记录制作树视图。所以,我使用了 Dynatree 来制作树视图。它工作正常。现在我想实现搜索功能。

如何使用 javascript 在 Visulforce 页面中制作 Dynatree 过滤器。

我想通过从文本字段中搜索来重新排列树。

我找到了过滤器的以下代码,但我不知道如何使用它。请让我知道我们应该在代码下方的哪里使用。

代码片段:

DynaTreeNode.prototype.search = function(pattern){

    if(pattern.length < 1 && !clear){
        clear = true;
        this.visit(function(node){
            node.expand(true);
            node.li.hidden = false;
            node.expand(false);
        });
    } else if (pattern.length >= 1) {
        clear = false;
        this.visit(function(node){
            node.expand(true);
            node.li.hidden = false;
        });

        for (var i = 0; i < this.childList.length; i++){
            var hide = {hide: false};
            this.childList[i]._searchNode(pattern, hide);
        }
    } 
},
4

1 回答 1

0

您可以使用以下功能根据您的搜索词过滤掉。

<input type="text" onchange="filterNodes(this.value);return false;" />

function filterNodes(searchTerm) {
        // Only show nodes matching the specified search term
        var startNode = $("#divTree").dynatree("getRoot");
        startNode.visit(function(node) {
            if (node.isVisible() && node.data.title) {
                // Filter currently visible non-root nodes.
                if (node.data.title.indexOf(searchTerm) >= 0) {
                    // Make sure we and all our parents are visible
                    node.visitParents(function(node) {
                        $(node.li).show();
                        return (node.parent != null);
                    }, true);
                    // Terminate the traversal of this branch since the node matches
                    return 'skip';
                }
                else {
                    // Hide the node.
                    $(node.li).hide();
                }
            }
        });
    }

如果发现一个节点匹配,这将过滤整个分支。

于 2015-05-08T09:09:50.920 回答