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

I made it possible to deep copy. #19

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hello holiber. I am a beginner web developer.

copy(entity) {
      return JSON.parse(JSON.stringify(entity));
}

because of here , functions of object vanish.

I used this module. https://www.npmjs.com/package/clone

var clone = require('clone');
copy(entity) {
    return clone(entity)
},
holiber commented 6 years ago

Hi. Thanks for your PR, however, I recommend to create an issue before you are going to add a new dependency to the project. For now, this project has no dependencies and for some developers, it is really important.

I prefer to keep the tree structure simple and serializable. That also allows to store the tree structure in a file or local-storage. If you need to have some additional UI handlers you can look at how show/hide buttons are implemented in the demo example. If you want to attach some unserializable data for this component you can link it via data property:

  var extaFunctions = {
    func1: () => { ... },
    func2: () => { .... }
  }

  var nodes = [
    {title: 'Item1', data: { extraFunction: 'func1' } },
    {title: 'Item2', data: { extraFunction: 'func2' } },
  ]

You also can create your own wrapper-component for sl-vue-tree for things like this