geekhybrid / vue3-tree-vue

MIT License
63 stars 22 forks source link

Getting id of the clicked item #2

Closed SciManJD closed 2 years ago

SciManJD commented 2 years ago

How can I get the id (that comes from the json data) of the item that was clicked? I receive the click event and probably it contains this information, but how to get it?

geekhybrid commented 2 years ago

@SciManJD

A user may interact with the tree by either selecting (one item at a time) or checking (multiple items).

To get the currently selected item (any item that was clicked).

You can do that for now by, binding to the selectedItem prop.

<vue3-tree-vue :items="items"
          v-model:selectedItem="selectedItem" />

Meanwhile, I will quickly add a feature that allows us simply listen to those events directly.

SciManJD commented 2 years ago

I know this option, but I need an event. I want to deliver the selection to another component. I can catch the event with @click and I get the @event in the called function, but how to find the id of the selected item?

geekhybrid commented 2 years ago

To do so, please update your package to version 1.0.13.

And use the onSelect event as specified in the README.

SciManJD commented 2 years ago

Thanks. It woks fine.