-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to delete a node using by id (unique) #66
Comments
the path of id 3 is [2]. // get removed id's
console.log(tree.getAllNodesByPath([2]))
// remove
tree.removeNodeByPath([2]) |
How to define the tree ? How can get
|
<Tree :value="treeData" ref="tree"></Tree> tree is a ref. check vue doc to get ref. |
Sorry forgot about ref :-) Here is the code https://codesandbox.io/s/gracious-thompson-u61v6?file=/src/App.vue When click to remove I want to remove by the id So in this case id 3
should remove the object with all the childrens (id 4, and id 5). And like I said .... need to know the ids (not index of the object) that he removed (in this case 3,4,5) to sync the other component. How can I do that ? |
function getNodeInfoByID(id) {
let found
tree.walkTreeData((node, index, parent, path) => {
if (node.id === id) {
found = {node, index, parent, path}
return false
}
})
return found
} |
Still not working what I am trying to do. I have updated the sandbox https://codesandbox.io/s/gracious-thompson-u61v6?file=/src/App.vue what works:
not working:
|
remove the square brackets of node.path const removeNode = (id) => {
let node = getNodeInfoByID(id);
console.log(node, id);
if (node) {
// get removed id's from the three
console.log(tree.value.getAllNodesByPath(node.path));
// remove all the data
tree.value.removeNodeByPath(node.path);
// remove all ids from selectedUsers model also
}
}; |
I have updated the code. I added some extra code and now works 👍 Thank you! |
I am using this in combination with a vue-select - multiple in vue 3.
When I select a user from the list it will push to treeData the object. Ex:
When remove an element from select I can get the object.
The issue that I have is I don't know how to use that function removenodebypath in composition api.
https://he-tree-vue.phphe.com/api.html#removenodebypath
It is possible to remove a node by id (which is unique) - (ex click of a button) and when the node is removed
(for ex id 3 - according to the treeData from above and it will also remove automatically id 4 and id 5) - and get those id's (all the id's that where removed) ?
Can you show me please how can I use removenodebypath and return the ids from the nodes that where removed ?
The text was updated successfully, but these errors were encountered: