You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[UTree] How to programmatically select UTree item? #6456
I need to synchronize selected item(s) in my Tree with current route. So when an item id=123 is selected, the route is #/items/123. Worst of all, I need it with multiple+bubbleSelect+selectionBehavior="replace".
You can imagine a file manager where Tree is the filesystem and current route is the filepath.
But how do I do the opposite? Route is updated -> select current item:
<script>
constsyncRoute= (item:TreeItem) =>router.push({name:'item', params: {id:item.id}})constselected= ref<TreeItem[]>([]);watch(router.currentRoute, currentRoute=> {constitemRoute=currentRoute.matched.find(candidate=>candidate.name==='item')if (itemRoute) {// how to select the item? }})
</script>
<template>
<UTree @update:modelValue="syncRoute"v-model="selected"/>
</template>
The issue above is I cannot simply put a TreeItem into selected.value as it must be the whole path from the item to tree root due to bubbleSelect. Looking at the source, Reka actually builds a tree structure internally and maintains parent prop which would make selecting with bubbleSelect easy, but it's not exposed outside.
One alternative is to give up on the "tree" aspect of UTree and completely make the tree structure myself. But I would like to reuse UTree to the max if possible.
Activity
[-][UTree] How to programmatically select an item?[/-][+][UTree] How to programmatically select UTree item?[/+]