holiber / sl-vue-tree

Customizable draggable tree component for Vue.js
https://holiber.github.io/sl-vue-tree/
MIT License
345 stars 78 forks source link

Handle selecting nodes via data #4

Closed Alex-Sokolov closed 6 years ago

Alex-Sokolov commented 6 years ago

Example:

<sl-vue-tree v-model="nodes" :allow-multiselect="false"></sl-vue-tree>

and somewhere selectedNode method:

selectedNode(node) {
  node.isSelected = true
}

When selecting node in sidebar — all ok, but if we select one node, and later somewhere change isSelected in nodes — will be two selected nodes.

How to handle selecting nodes outside component, from data?

holiber commented 6 years ago

Hi. You can use traverse method to change the original model:

slVueTree.traverse((node, nodeModel, path) => {
    Vue.set(nodeModel, 'isSelected', true);
})

Also you can try to use select method

slVueTree.select(node)

However this is an undocumented method and it is going to be changed in next versions

holiber commented 6 years ago

@Alex-Sokolov you can upgrade and try select(path) method from v1.5.0