question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

path in removeNode

See original GitHub issue

I try remove my Node, how I can get path in my case?

export default class TreeVera extends Component {
    constructor(props) {
        super(props);
        this.updateTreeData = this.updateTreeData.bind(this);
        this.removeNode = this.removeNode.bind(this);
        this.state = {
            treeData: [{
                title: (<div>
                        <input />
                        <button onClick={this.removeNode}>remove</button>
                    </div>),
            }]
        };
    }
    removeNode(e){
        this.setState({
               treeData: removeNodeAtPath({
                   treeData: this.state.treeData,
                   path: ????,
                   getNodeKey: ({node: TreeNode, treeIndex: number}) => {
                       console.log(number);
                       return number;
                   },
                   ignoreCollapsed: false,
               })
        })
    }
    updateTreeData(treeData) {
        this.setState({ treeData });
    }
    render() {
        return (
            <div style={{ height: 600 }}>
                <SortableTree
                    treeData={this.state.treeData}
                    onChange={this.updateTreeData}
                />
            </div>
        );
    }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
anil1712commented, Feb 12, 2017

Try to use generateNodeProps to create delete button.

<SortableTree
     treeData={this.state.treeData}
     onChange={treeData => this.onChange(treeData)}
     generateNodeProps={rowInfo => ({
         buttons: [
                   <Button label='Delete'
                            onClick={(event) => this.removeNode(rowInfo)}/>,
                ],
      })}

removeNode(rowInfo) {
    let {node, treeIndex, path} = rowInfo;
    removeNodeAtPath({
                   treeData: this.state.treeData,
                   path: path,   // You can use path from here
                   getNodeKey: ({node: TreeNode, treeIndex: number}) => {
                       console.log(number);
                       return number;
                   },
              ignoreCollapsed: false,
           })
}

I am using the same way but some how getting below exception in browser console Uncaught (in promise) Error: No node found at the given path. Let me know if its working for you

@fritz-c can you please check am I doing something wrong.

Thanks,

1reaction
nguyenthuccommented, Nov 18, 2021

@hungnguyen1412
You can to set newNode : {… currentNode, ItemNode }, removeNodeAtPath({ treeData: treeData, path: myPath, getNodeKey: ({ treeIndex }) => treeIndex, newNode: { …currentNode, ItemNode }, ignoreCollapsed: false }) Working for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove node in react-sortable-tree - Stack Overflow
I solved this problem: export default class Tree extends Component { constructor(props) { super(props); this.updateTreeData = this.
Read more >
Remove all nodes which don't lie in any path with sum>= k
Given a number K, you have to remove (prune the tree) all nodes which don't lie in any path with sum>=k. Note: A...
Read more >
Remove "node" From Menu Path Using Clean URLs | Drupal.org
I have clean URLs enabled. When attempting to create menu items I am unable to define a path without the term "node". Example:...
Read more >
JSON Remove Node
You can specify the node to remove using a JSON Path expression. The JSON Path query language enables you to select nodes in...
Read more >
Find all paths in a graph when removing one node of the ...
Wolfram Community forum discussion about Find all paths in a graph when ... Then start over with the original graph and remove node...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found