Perspective event with Tree component

Hello, I am using the Tree component in perspective.
I want to click on one of the buttons in the Tree component to enable a light by using the Events. However, In a tree component, there are many buttons, how can I specify the button in Event? Because right now I am using onClick, so I click on anywhere the tree component the light will enable. Should I use onClick or onContexMenu? Thanks

1 Like

Use the onItemClicked Event. This Event type provides access to the itemPath and label of the item which was clicked.

Hello, can you give an example of using the onitemclicked? I haven’t found any description of how to use it. I primarily looking for how to address a specific button on the Tree. Thanks!

onItemClicked should almost always be used with a Script Action.

I have my Event configured like this:

My View looks like this:

If I click “LightOn”:

if I click “LightOff”:

In this example, the tree is very simple and so there is no risk of repeated label text. In the event your tree is more complicated, I recommend using the itemPath property available to you as part of the Event. The itemPath contains a list of the indices which lead to the selected item.

In my example if I were to click the “LightOff” item, I would receive an itemPath value of [0, 0, 1] because “LightOff” is the one-eth item found within the zeroeth item, within the zeroeth item. The list translates like this:

0    |    Item 1
0    |    Lights
1    |    LightOff


I got it works, thank you!

1 Like