Deeper level tree issue
VasilisNikiforidis opened this issue · 5 comments
Hi!
I tried deleting some items from a nested tree I created, but it failed beyond the 1st split.
My code:
getDeletedItem(item,name){
var flatName = item.parent.text+"/"+name
if(Object.keys(item.parent.parent).includes('text')){
console.log(Object.keys(item.parent))
flatName = this.getDeletedItem(item.parent,flatName)
}
return flatName
}
deleteMenuItem(name) {
var item = this.$refs.tree.getNodeById(name)
this.$refs.tree.deleteNode(item)
console.log(this.getDeletedItem(item,item.text))
}
Part of my tree is like this:
parent1
parent2
child1
parent3
child2
parent4
parent5
child3
My problem is that when i use getNodeById(name) (where name is the Id i set for each item) I get an object with only the direct parent and when I expand parent in the console to see what is in there, there is no additional parent item as I would expect.
For example in the above schema, getNodeById for child1 has parent item with details for parent2 but parent 2 does not include a parent item for parent1.
Though when I print the whole tree I do not have this issue.
Any help is appreciated.
can you make a demo on codesandbox or codepen?
I can't seem to reproduce it on codepen for some reason, though I have noticed that the id's, which I set at the creation of the tree to be the same as the 'text' field are being reset to their default.
Maybe sth to do with my tree data being return in a computed property?
maybe
did you manage to solve your problem ? I am running into the same one so any advice would be really appreciated, thanks !
@roxanerg If I recall correctly, I solved my issue by flattening the tree delete any item I needed to, and then unflatten. Unfortunately I do not have access to the code right now, but I think this was the general idea. Hope it helps!