mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #246] The .Walk() functionality on a tree view always returns the parent as nil #191
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#191
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @thebsdbox on GitHub (Mar 4, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/246
Unless I'm doing this wrong I don't seem to be able to walk up the tree, I'm trying to find the parent with the reference I'm expecting.
Example below, I need to be able to walk the
pre-bootSnapshot up the tree to it's parent with the expected referencevirtual machinewhich maps to a VM namedserver05where I can then perform the expected action.@thebsdbox commented on GitHub (Mar 5, 2019):
Ended up using a struct that carries a pointer back to the VM and pinning it to child nodes with
SetReference(v), I presume thats the way to go. (works for me :) )@rivo commented on GitHub (Mar 9, 2019):
Internally, tree nodes do not keep a reference to their parents, only to their children, i.e. top-down. The
TreeNodeclass gives you a lot of freedom to callSetChildren()orAddChild()anywhere and I didn't want to get into the mess of keeping children and parents in sync. (I'm not even sure if this is possible, e.g. if you use the sameTreeNodemultiple times.)The only way to access a parent within
tviewis to use theWalk()function and then it's only temporary and returnsnilfor the node you callWalk()on (see documentation). You'd have to callWalk()on the root node (which may be inefficient for your case).So yeah, you'll have to resort to keeping a reference to the parent by yourself, as you do.
I'll close this for now. If you want to keep the discussion going, we can always reopen this issue.