he-tree icon indicating copy to clipboard operation
he-tree copied to clipboard

Adding a node programmatically has bugs

Open superchairon opened this issue 3 years ago • 1 comments

Hello.

First let me tell you, your component is great!!!

I want to add a node programmatically to the root. Currently the addNode() method works, passing a simple object as parameter, but the new node is not reactive, I cannot expand or collapse it (e.g. lazy loading does not work) I also tried adding the node to the original data pointed by treeData but then the lazy loading does not work either.

What is the right wat to add a node with code?

superchairon avatar Jun 30 '22 18:06 superchairon

Yes, it works in Vue3, with bug in Vue2. After addNode called, try follow code make properties reactive.

Object.keys(node).forEach(key => {
  this.$set(node, key, node[key])
});

phphe avatar Jul 06 '22 09:07 phphe