• Find the key of all the parent nodes of the target node

    Example

    import { findParentKeysByKey } from "tree-handle-lib";
    const tree = [
    {
    key: 'a',
    children: [
    { key: 'b' },
    { key: 'c', children: [{ key: 'd' }] },
    ],
    },
    { key: 'e' },
    { key: 'f', children: [{ key: 'g' }] },
    ];
    const _result = findParentKeysByKey(tree, 'd')
    // ["a","c"]

    Parameters

    • node: TNode

      the root node of the tree,can be a single node or an array of nodes

    • key: string

      the key of find the destination node

    • childrenName: string = CHILDREN_NAME

      the child key name of the child node in the tree structure,default value is CHILDREN_NAME='children'

    • keyName: string = KEY_NAME

      the key name of the node in the tree structure,default value is KEY_NAME='key'

    • isAddCurrentKey: boolean = false

      append the current key after the return result key list

    Returns string[]

Generated using TypeDoc