mbraak / jqTree

Tree widget for jQuery
https://mbraak.github.io/jqTree/
Apache License 2.0
1.02k stars 177 forks source link

How to apply a search box in this jqTree? #211

Closed xiaods closed 11 years ago

xiaods commented 11 years ago

Dose anyone can give some hints? thanks a lot.

one-err1

mbraak commented 11 years ago

In our own code we do this:

$('#search').click(
    function() {
        var $tree = $('#tree1');
        var search_term = 'xyz';

        var tree = $tree.tree('getTree');

        tree.iterate(
            function(node) {
                if (node.name.indexOf(search_term) == -1) {
                    // Not found, continue searching
                    return true;
                }
                else {
                    // Found. Select node. Stop searching.
                    $tree.tree('selectNode', node, true);
                    return false
                }
            }
        );
    }
);
xiaods commented 11 years ago

@mbraak good point. it works like a charm.