# Perspective event with Tree component

**URL:** <https://forum.inductiveautomation.com/t/perspective-event-with-tree-component/36968>\
**Category:** Ignition\
**Created:** [July 22, 2020, 9:52pm UTC](https://forum.inductiveautomation.com/t/perspective-event-with-tree-component/36968 "2020-07-22T21:52:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbai1](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@mbai1](https://forum.inductiveautomation.com/u/mbai1)\
**Post date:** [July 22, 2020, 9:52pm UTC](https://forum.inductiveautomation.com/t/perspective-event-with-tree-component/36968/1 "2020-07-22T21:52:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 23, 2020, 5:59am UTC](https://forum.inductiveautomation.com/t/perspective-event-with-tree-component/36968/2 "2020-07-23T05:59:03Z")

</div>

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

 ![Screen Shot 2020-07-22 at 10.58.27 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/1/311f3d15063a33f4ab925b2ad6f7f31846906f04.png)

---

<div class="post-metadata">

**Author:** ![mbai1](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@mbai1](https://forum.inductiveautomation.com/u/mbai1)\
**Post date:** [July 23, 2020, 2:06pm UTC](https://forum.inductiveautomation.com/t/perspective-event-with-tree-component/36968/3 "2020-07-23T14:06:12Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 23, 2020, 2:34pm UTC](https://forum.inductiveautomation.com/t/perspective-event-with-tree-component/36968/4 "2020-07-23T14:34:40Z")

</div>

`onItemClicked` should almost always be used with a Script Action.

I have my Event configured like this:

 ![Screen Shot 2020-07-23 at 7.25.27 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/f/0f43d0956a08edd5d9da5bf9532f05c912e32733.png)

My View looks like this:

 ![Screen Shot 2020-07-23 at 7.24.52 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/e/5e685eec16deaaf585d6d4fa5bb2ee50e7a8448b.png)

If I click “LightOn”:

 ![Screen Shot 2020-07-23 at 7.25.07 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/8/a8470792d851c6c9d8ffc65a98b0c283897851ab.png)

if I click “LightOff”:

 ![Screen Shot 2020-07-23 at 7.25.13 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/c/8ca0309106f28db215897b819133fb03df8cbb34.png)

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:

```auto
0 | Item 1
0 | Lights
1 | LightOff

```

 ![Screen Shot 2020-07-23 at 7.33.31 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/1/6151ec7764cb7a4747d7f168b18fd3b4c0965933.png)

---

<div class="post-metadata">

**Author:** ![mbai1](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@mbai1](https://forum.inductiveautomation.com/u/mbai1)\
**Post date:** [July 23, 2020, 2:40pm UTC](https://forum.inductiveautomation.com/t/perspective-event-with-tree-component/36968/5 "2020-07-23T14:40:57Z")

</div>

I got it works, thank you!
