frontend-collective / frontend-collective/react-sortable-tree
Dynamically Add/Clone New Nodes which includes children and sub-children
- Dominant language
- JavaScript
- Stars
- 5k
- Forks
- 914
- PR merge metrics
- No merged PRs in 30d
Description
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
})
}
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.