David-Desmaisons / Vue.D3.tree

Vue component to display tree based on D3.js layout.
https://david-desmaisons.github.io/Vue.D3.tree/tree
MIT License
877 stars 136 forks source link

How to insert nodes dynamically when a father node is clicked ? #23

Closed Wenzel closed 6 years ago

Wenzel commented 6 years ago

Hi @David-Desmaisons ,

I was wondering how it could be possible to insert new nodes dynamically (fetched from an external resource, like a GraphQL endpoint), when the root node is being clicked.

So far, I tried the following:

    <tree :data="tree" node-text="name" class="tree" v-on:clicked="onClicked">
    </tree>
  methods: {
    onClicked: function (event) {
      alert('Bonjour ' + this.tree.name + ' !')
      var child = {
        name: 'child01'
      }
      event.data.children.push(child)
    }
  }

And the data is indeed updated: screenshot from 2018-08-09 11-42-06

And reflected on the Component tree attribute: screenshot from 2018-08-09 11-42-53

-> So Is it a simple refresh problem ? -> Can I use your component to insert dynamical data into it, or should i gather all the data from the beginning ?

Thanks David !

Wenzel commented 6 years ago

I find this similar issue in the closed ones: https://github.com/David-Desmaisons/Vue.D3.tree/issues/15

But i doesn't help me much here.

David-Desmaisons commented 6 years ago

Correct in version 3.6.0.