react-sortable-tree icon indicating copy to clipboard operation
react-sortable-tree copied to clipboard

Dynamically Add/Clone New Nodes which includes children and sub-children

Open harishmegharaj opened this issue 5 years ago • 1 comments

I have a scenario, were need to create new nodes dynamically from a recursive function. Is it possible to achieve it? Please find the code which I tried, it throws an error "No node found with the given key."

function recursive(obj, rinfo) {
       let temprowInfo = self.state.copyPasteRowInfo;
        self.addNewNode(obj, rinfo);
        if (obj.children && obj.children.length) {
            obj.children.forEach(a => recursive(a, temprowInfo));
        }
    }
recursive(fData, rowInfo)

addNewNode(rowthing, rowInfo) {
    let ADD_NEW_NODE = { ...rowThing };
    let { node, treeIndex, path } = rowInfo;
    let path_new = rowInfo.path;
    let getNodeKey = ({ node: object, treeIndex: number }) => {
        return number;
    };
    let newTree = addNodeUnderParent({
        treeData: this.state.treeData,
        parentKey: path_new[path_new.length - 1],
        expandParent: true,
        getNodeKey,
        newNode: ADD_NEW_NODE
    });
    rowInfo.parentNode = { ...tempObj };
    rowInfo.node = { ...ADD_NEW_NODE };
    rowInfo.treeIndex = newTree.treeIndex;
    let temppath = rowInfo.path || [];
    if (temppath.length > 0) {
        temppath.push(rowInfo.treeIndex);
    }
    rowInfo.path = temppath;
    this.setState({
        copyPasteRowInfo: rowInfo
    })
}

harishmegharaj avatar May 03 '19 04:05 harishmegharaj

I am also facing an issue when i clone a node and changes value of input in it it reflects the both my original and the cloned one

UzairSamad avatar Dec 08 '21 07:12 UzairSamad