phphe / vue-draggable-nested-tree

Vue2 draggable tree component
https://hetree.phphe.com/
MIT License
345 stars 62 forks source link

Fix for: push with childs #38

Closed FlameArtLab closed 5 years ago

FlameArtLab commented 6 years ago

If we push any item with childs to Data, like this in Base Example:

     this.originalData.push({text: "HELLO", children: [{text: "HELLO 2"}]})

we get an error "TypeError: Cannot read property 'level' of undefined"

Fix for that in TreeNode.vue->watch handler, need to add recursive init for new arrays:

insert

        th.breadthFirstSearch(data, (node, k, parent) => {
          if(parent===undefined) parent=this.$parent.data;
          data._vm.store.compeleteNode(node, parent)
        });

instead of just

        this.store.compeleteNode(data, this.$parent.data)

edited: fixed top level parent definition

Now, it works good

phphe commented 5 years ago

fixed in 2.1.8

FlameArtLab commented 5 years ago

Thanks!