Q-tree how to get selected node on checkbox click when using tickable nodes option



  • This is my Qtree element, data is an Array and the tree loads up correctly.

    <q-input v-model=“filter” stack-label=“Filter” clearable class=“q-mb-sm”/>
    <q-tree
    :nodes=“data”
    color=“secondary”
    node-key = “id”
    accordion
    ref=“tree”
    :filter=“filter”
    :ticked.sync=“ticked”
    :tick-strategy=“tickStrategy”>
    </q-tree>

    I am unable to get any event trigger on checkbox click which gives me the current node. The examples also do not show how to handle tree events. Can someone please help?



  • You don’t have an event in your tree component. Are you using v1 or 0.17?

    Scott



  • I am using v0.17. Actually, I was able to get the checkbox click event using @update:ticked=“callback” in my tree definition shown below.

    <q-tree
    :nodes=“dataObj”
    color=“secondary”
    node-key = “id”
    accordion
    ref=“tree”
    @update:ticked=“callback”
    :filter=“filter”
    :ticked.sync=“ticked”
    :tick-strategy=“tickStrategy”
    >
    </q-tree>

    I have a follow-up question though. I want to do some operations when a is node checked and also when a node is unchecked.

    When the node is checked I get the node correctly in callback function argument and am able to carry out the operation(turn on a layer on map).
    But, when it is unchecked I do not get unchecked items in callback argument. I want to find the unchecked item so I can do the corresponding operation(turn off layer on map).

    Is there a way to get an unchecked item from Qtree?



  • I wouldn’t do it with events.
    Maybe you could use a vue-watcher for the ticked array.



  • Yes, I understand watcher would help as I can compare new value and old value and get the unchecked items as a difference of the two. I wanted to avoid putting a watcher on ticked array as it would make the operation expensive as watcher keeps checking for every change in value. If no alternative then maybe watcher is the way.


Log in to reply