How to iterate walk through recursively the perspective tree below
To output dataset:
Reason:
I need to be able to highlight desired label.
Grandchild 2 is 0/0/1
How to iterate walk through recursively the perspective tree below
To output dataset:
Reason:
I need to be able to highlight desired label.
Grandchild 2 is 0/0/1
Your question is really, "Can someone suggest code to create a list of Tree component item paths and their labels from the tree's props.items
?"
My question is, "Why would you want to?" It's much more likely that you would be creating the items lists by code (as you have asked in recent questions).
On the other part of the view, I have another navigation logic, and I want this to sync with tree logic, be able to highlight the current path on the tree.
Amazingly, I think I am almost there (I hope so), just randomly code:
def walk(items, k):
for i in range(len(items)):
k+=str(i) + "/"
system.perspective.print(k)
system.perspective.print(items[i]['label'])
if len(items[i]['items']) > 0:
walk(items[i]['items'], k)
else:
system.perspective.print('end ' + k)
k = k[:len(k)-2]
listOfObj = self.getSibling("Tree_0").props.items
k=""
walk(listOfObj, k)
Output:
So you have 2 different navigation schemes, and you want them to be in sync.
What's the other method ?
Also, just a shot in the dark as we don't know much about your project, but... could the mainview
page props be enough ?
I've seen convoluted ways of identifying what view is being displayed in order to highlight something, when all that was really needed was to compare the navigation target of an element to the mainview
prop. Maybe you're in that situation.
This.
Addition to tree, I got a parentBar, and children view. Using flex repeaters.
When the child is clicked, the new parent will be current parentPath + childPath. And will drive the views and highlight on the tree accordingly.
I use this {this.custom.view} = {page.props.primaryView}
in an expression to highlight the button that corresponds to the current view. this
is the button, and it has a custom property view
that's just the path of the view to navigate to.
If you're using a view based navigation then it should work for you as well. No need to do complicated things from either menu to keep them in sync.