[solved] given a leaf in a q-tree, how can I programmatically select a leaf and open all parents?
rconstantine last edited by rconstantine
I’ve been trying to figure out how to use setExpanded to programmatically expand all parent nodes in a q-tree, but I’m stumped.
I hesitate to show what I’ve tried since nothing even comes close to working.
Has anyone done this before?
I thought I had multiple levels, but I only had two. I discovered the method “getNodeByKey” which is part of q-tree. That’s all I needed to solve my issue. Elsewhere, I am adding a ‘parentID’ to the node as the tree is created and calling the getNodeByKey(ID).parent using the ID of the selected item gets me the parent ID and I can then set it to expanded.
BTW, would be nice to add getNodeByKey to the documentation.
@rconstantine - getNodeByKey is documented in https://quasar.dev/vue-components/tree#QTree-API, under the “Methods” tab.
If you use Mongoose in your backend code, you may want to have a look at this package to more easily manage your tree structures:
I haven’t used it yet together with q-tree, but plan to do so.
!!! it was the first one listed in methods! How did I miss it?
Anyway, I’m using the API from an existing website, so can’t change how anything is served to me. Thanks for the idea though.