• Insert node after the destination node

    Example

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

    Parameters

    • node: TNode

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

    • key: string

      the key of the node before the insertion position

    • insertNodes: 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