• Find destination node by key

    Example

    import { findNodeByKey } from "tree-handle-lib";
    const treeData = [
    {
    key: 1,
    name: "A",
    children: [
    {
    key: 2,
    name: "B",
    },
    {
    key: 3,
    name: "C",
    children: [
    {
    key: 4,
    name: "D",
    },
    {
    key: 5,
    name: "E",
    },
    ],
    },
    ],
    },
    ];
    const _result = findNodeByKey(treeData, 3);
    // {
    // key: 3,
    // name: "C",
    // children: [
    // { key: 4, name: "D" },
    // { key: 5, name: "E" },
    // ],
    // };

    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'

    Returns TTreeNode

    node | null

Generated using TypeDoc