• Update the nodes by keys and update function

    Example

    import { updateNodes } from "tree-handle-lib";
    const node = [{ key: 1, name: "foo", children: [{ key: 2, name: "bar" }] }];
    const update = (node) => ({ name: node.name.toUpperCase() });
    const result = updateNodes(node, update, [2]);

    // console.log(JSON.stringify(result))
    [
    { key: 1, name: "foo", children: [{ key: 2, name: "BAR" }] }
    ];

    Parameters

    • node: TNode

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

    • update: Object | Function

      the obj which can merged into the destination node

    • keys: string[] = null

      the key list of update node, if null, it will update All nodes

    • 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