Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to replace the entire tree? #73

Open
sunh11373 opened this issue Oct 8, 2020 · 12 comments
Open

How to replace the entire tree? #73

sunh11373 opened this issue Oct 8, 2020 · 12 comments

Comments

@sunh11373
Copy link

Is it possible to replace the entire tree?

If I do it naively as below:

<template>
<tree  :data="myTree" ....>

<script>
...resplaceTree() {
       this.myTree = <newTree>

I got similar error:

client.js:96 TypeError: Cannot read property 'x' of undefined
    at e (index.js:1)
    at SVGPathElement.<anonymous> (index.js:2)
    at SVGPathElement.<anonymous> (attr.js:29)
    at Selection.each (each.js:5)
    at Selection.attr (attr.js:53)
    at VueComponent.updateGraph (index.js:2)
    at VueComponent.<anonymous> (index.js:2)
    at Array.<anonymous> (vue.runtime.esm.js:1980)
    at flushCallbacks (vue.runtime.esm.js:1906)

Btw, if myTree is initially null, it works.

-thanks

@Joun-lee
Copy link

@sunh11373 Hi, Please have a look at the closed issue #54. Use the prop identifier can solve your problem.

@sunh11373
Copy link
Author

Not sure how this can be resolved with "prop identifier". I need to replace the tree with a total different set of data with different number of nodes.

-thanks

@NoAbdulrahman
Copy link

Hi @sunh11373 @Joun-lee Did you solve the problem? If yes, could you please tell me how to do? I have a similar problem and I don't understand how to solve it with the props identifier

@Joun-lee
Copy link

Joun-lee commented Dec 3, 2020

Hi, @NoAbdulrahman You can try my code below, see if it can solve your problem.

The html part

        <tree
          :data="currentRegionTree" 
          :duration="200"
          node-text="name"
          :identifier="getId" //this is a function defined in your 'methods' section
          layoutType="horizontal"
          type="tree"
          :zoomable="true"
          linkLayout="orthogonal"
        ></tree>

In the methods section of your vue component

   getId(node) {
      return node.id;
    }

@NoAbdulrahman
Copy link

NoAbdulrahman commented Dec 3, 2020

@Joun-lee Thanks, I used the identifier, I have no error now, but the tree is still not displayed. I don't know if I'm missing something. Here is my code if you could have a look.
The html part:

<tree :data="tree"  :identifier="getId"  node-text="title"  layoutType="horizontal"
       type="tree"   Duration="0"  style="width:600px; height:600px" ...>
</tree>

The script:

export default Vue.extend({
  name: "Products",
  components: {
       tree,
  },
  data() {    
      return {     
             tree:{}
    };},
async created(){
         const products = await this.FetchedData();
         this.tree=products;
  console.log(this.tree);
},
methods: {
      async FetchedData(){
        let response = await Service.getProducts()
        let products = response.data.data;
        products=  JSON.stringify(products);
        return products
       },
       getId(node) {
       return node.id;
    }, });

@Joun-lee
Copy link

Joun-lee commented Dec 3, 2020

Hi, @NoAbdulrahman Not sure why, but i would suggest you first check the 'tree' value, does it comply with the rule? Might use some simple static data firstly to check that, for example use the data below

tree: {
        name: "father",
        children:[{
          name: "son1",
          children:[ {name: "grandson"}, {name: "grandson2"}]
        },{
          name: "son2",
          children:[ {name: "grandson3"}, {name: "grandson4"}]
        }]
      }

@NoAbdulrahman
Copy link

@Joun-lee Thanks for your reply. The tree is displayed very well when I use my data as static, but it is not displayed when I try to fetch the same data from the API. The "console.log" in created() prints the data which means the data is fetched correctly, but I don't know why the tree is not displayed.

@NoAbdulrahman
Copy link

Hi @David-Desmaisons , Do you have an idea about my issue above?

@Joun-lee
Copy link

Joun-lee commented Dec 4, 2020

Hi @NoAbdulrahman , usually I fetch data in the mounted function, maybe you can try do it in your mounted function.

@David-Desmaisons
Copy link
Owner

Using mount or created should not make any diference.
@NoAbdulrahman From waht you are describing nothing I can do. Try to check the example and apdat them.
It looks like something related on the data you are using not the component itself.

@NoAbdulrahman
Copy link

My problem is solved by adding v-if=“dataLoaded” on the tree component and set the dataLoaded property to true loading the data. Also, I had to use json object instead of json string.

@horikx
Copy link

horikx commented Jun 25, 2021

@NoAbdulrahman I have the same problem. It renders the first time but when I completely change the dataset I get the same error. If the Vue component is destroyed then recreated it works, but you can't just change the data. I did this by applying a key to the tree and changing it everytime the dataset changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants