JQuery Dynatree - search node by name

后端 未结 4 1764
清酒与你
清酒与你 2020-12-09 22:01

I would like to start using Dynatree on my page, however I will probably need searching my tree by name. Do you know maybe how to do this?

4条回答
  •  温柔的废话
    2020-12-09 22:30

    Thanks to @mar10 i made a small, simple function to search a node with title:

    // If searchFrom is null, root is used
    function seachFolderNodeWithName(name, searchFrom) {
        if (name == null) {
            return undefined;
        }
    
        if (searchFrom == null) {
            searchFrom = jQuery('#tree').dynatree("getRoot");
        }
    
        var match = undefined;
    
        searchFrom.visit(function (node) {
            if (node.data.title === name) {
                match = node;
                return false; // Break if found
            }
        });
        return match;
    };
    

提交回复
热议问题