Hi @Oliver and thank you for your peply.
> Do you have an example of a use case for this? <
Sure, please conside that menù tree.
Root --> command --> Cancel
-> Lastp op
--> Last 5 ops
--> All
--> Mark to be --> Deleted
--> Renamed
--> Copyied
--> Send
--> Other Stuff --> Navigate to --> Facebook page
--> Tweeter page
Style the page --> Random body color
--> Zoom In
--> Zoom Out
--> Credits
Let's assume that the id of each menu item (parent and child) is composed of the description from which the spaces are removed and the initial letters are capitalised.
Each leaf of this tree would have the pathMenuitemId property set like this:
01 Command~Cancel~LastpOp
02 Command~Cancel~Lastp5Ops
03 Command~Cancel~All
04 Command~MarkToBe~Deleted
05 Command~MarkToBe~Renamed
06 Command~MarkToBe~Copied
07 Command~Send
08 OtherStuff~NavigateTo~FacebookPage
09 OtherStuff~NavigateTo~TweeterPage
10 OtherStuff~StyleThePage~RandomBodyColor
12 OtherStuff~StyleThePage~ZoomIn
13 OtherStuff~StyleThePage~ZoomOut
14 Credits
Let's say I wants to do something when the user clicks on one of the first 7 leaves.
The most efficient thing I can think of is to check if menuParentItemId is between "Cancel", "MarkToBe" and "Command"
so the test can be written like this
["Cancel", "MarkToBe", "Command"].includes(info.parentMenuItemId)
...but I had a new pathMenuitemId property I could have written differentlylike:
pathMenuitemId.split("~").includes("Command")
If we consider that the tree can be destroyed, rebuilt and still change dynamically based on the user's choices\iterations (the developer may not have saved (or lost) the current tree structure)
it would be much easier then to check tree branches like: pathMenuitemId.split("~").length == 3
(that is:
tree leaves that have a parent and also grandparents)
)
How else could this last condition be written with only the "menuItem" and "menuParentItem" properties?