• Sorts the tree nodes based on the specified field

    Example

    import { sortNodeByName } from "tree-handle-lib";
    const nodes = [
    { title: "b", children: [] },
    { title: "a", children: [{ title: "d" }, { title: "c" }] },
    { title: "f", children: [] },
    ];
    const _result = sortNodeByName(nodes, "title");
    console.log(JSON.stringify(_result));
    // [
    // { title: "a", children: [{ title: "c" }, { title: "d" }] },
    // { title: "b", children: [] },
    // { title: "f", children: [] },
    // ];

    Parameters

    • node: TNode

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

    • sortKeyName: string = TITLE_NAME

      the attribute name of node for sort tree node,default is TITLE_NAME='title'

    • childrenName: string = CHILDREN_NAME

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

    Returns TNode

Generated using TypeDoc