• Insert child node in destination node by parentKey

    Example

    import { insertChild } from "tree-handle-lib";
    const node = [
    { key: "1", children: [{ key: "2" }, { key: "3" }] },
    { key: "4", children: [{ key: "5" }] },
    ];
    const insertNode = { key: "6" };
    const _result = insertChild(node, "1", insertNode);
    // [
    // { key: "1", children: [{ key: "2" }, { key: "3" }, { key: "6" }] },
    // { key: "4", children: [{ key: "5" }] },
    // ];

    Parameters

    • node: TNode

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

    • parentKey: string

      the key of the parent node to be inserted at

    • insertNodes: TTreeNode | TTreeNode[]

      the nodes to insert into the tree

    • 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 any

Generated using TypeDoc