Skip to content

How to update v-model in BaseTree #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thensanity opened this issue Mar 27, 2025 · 6 comments
Closed

How to update v-model in BaseTree #152

thensanity opened this issue Mar 27, 2025 · 6 comments

Comments

@thensanity
Copy link

thensanity commented Mar 27, 2025

`








<v-text-field
label="Search Contract"
v-model="search"
color="secondary"
hide-details
clearable
clear-icon="mdi-close-circle-outline"
@input="filterTreeData">


         <BaseTree ref="tree" 
         class="bgc-white mtl-tree" 
         v-model="filteredTreeData" 
         virtualization 
         :default-open="false"
         @open:node="fetchChildData">
  <template #default="{ node, stat }">
    <OpenIcon
       v-if="!node.isContractDate"
      :open="stat.open"
      class="mtl-mr"
       @click="stat.open = !stat.open"
        />

     <input
      class="mtl-checkbox mtl-mr"
      type="checkbox"
      v-model="stat.checked"
      v-if="node.isContractDate"
      @change="onSelected(node)"
    />
   
    {{ node.name }}
  </template>
</BaseTree>
       
    </div>
  </v-dialog>
  </v-col>
</v-row>

`

I have a BaseTree component with a v-model bound to filteredTreeData.
I'm facing an issue where, when I dynamically update the tree nodes bound to filteredTreeData through the open:node event, I can see filteredTreeData is updated with the new children of the node when it opens (as confirmed in the Dev Tools), and also vue watchers also showing filteredTreeData nodes is updated with new chidlren.
However, the UI does not reflect these updates immediately. The updated nodes only appear when the tree is re-initialized. What could be the issue here?

Image
@phphe
Copy link
Owner

phphe commented Mar 27, 2025

it only watch v-model object self's change.

@thensanity
Copy link
Author

Are there any other ways to refresh the node so it shows its updated children when the open:node event triggers?

@phphe
Copy link
Owner

phphe commented Mar 27, 2025

use inner methods to update node: https://hetree.phphe.com/v2/api#methods

@thensanity
Copy link
Author

ok, thanks.

I just checked the documentation, but there are no update node methods available currently ?

The add method would not suffice as it will replace the whole state. All I want is to replace the existing children with new children.

@phphe
Copy link
Owner

phphe commented Mar 27, 2025

you can record state in your node, then use https://hetree.phphe.com/v2/api#stathandler restore them when init the node

@thensanity
Copy link
Author

ok, i got the idea how to handle all kind of situations, thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants