vue-draggable-nested-tree icon indicating copy to clipboard operation
vue-draggable-nested-tree copied to clipboard

Deeper level tree issue

Open VasilisNikiforidis opened this issue 6 years ago • 5 comments
trafficstars

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.

VasilisNikiforidis avatar Apr 08 '19 09:04 VasilisNikiforidis

can you make a demo on codesandbox or codepen?

phphe avatar Apr 08 '19 10:04 phphe

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?

VasilisNikiforidis avatar Apr 08 '19 15:04 VasilisNikiforidis

maybe

phphe avatar Apr 09 '19 02:04 phphe

Hi @VasilisNikiforidis,

did you manage to solve your problem ? I am running into the same one so any advice would be really appreciated, thanks !

roxanerg avatar Aug 21 '19 19:08 roxanerg

@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!

VasilisNikiforidis avatar Aug 21 '19 20:08 VasilisNikiforidis