Skip to content
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

Deeper level tree issue #67

Open
VasilisNikiforidis opened this issue Apr 8, 2019 · 5 comments
Open

Deeper level tree issue #67

VasilisNikiforidis opened this issue Apr 8, 2019 · 5 comments

Comments

@VasilisNikiforidis
Copy link

VasilisNikiforidis commented Apr 8, 2019

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.

@phphe
Copy link
Owner

phphe commented Apr 8, 2019

can you make a demo on codesandbox or codepen?

@VasilisNikiforidis
Copy link
Author

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?

@phphe
Copy link
Owner

phphe commented Apr 9, 2019

maybe

@roxanerg
Copy link

Hi @VasilisNikiforidis,

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

@VasilisNikiforidis
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants