Code Monkey home page Code Monkey logo

Comments (25)

phphe avatar phphe commented on May 17, 2024 3
import {walkTreeData} from 'he-tree-vue'
...
getItemgroupsTree() {
                Itemgroup.fetchTree(308)
                    .then(data => {
                        this.item_groups_tree = data.item_groups_tree;
                        walkTreeData(this.item_groups_tree, node => {
                            this.$set(node, '$folded', true)
                        })
                    })
                    .catch(error => {});
            },

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

foldAllAfterMounted is false default, so the children tree is unfolded default. so your code is equal to default.
The follow code will fold all after mounted

<Tree :value="treeData" foldAllAfterMounted>

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Here is my updated code:

<Tree :value="item_groups_tree" foldAllAfterMounted>
    <span slot-scope="{node, index, path, tree}">
      <b @click="tree.toggleFold(node, path)">
        {{node.$folded ? '+' : '-'}}
      </b>
        {{node.Name + ' ('+node.SystemKey+')'}}
    </span>
</Tree>

Here is the output image. foldAllAfterMounted is true now but didn't collapse the tree.
image

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

The tree mounted, then it try fold existed data. The data added after that will not be folded. The source code is at fold.js like follow:

mounted() {
    if (this.foldAllAfterMounted) {
      this.foldAll()
    }
  },

So you can call tree.foldAll() manually.

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Thanks so much for your reply.

I tried to use tree.foldAll() in mounted() and template. but didn't work. Could you please show me how I could use tree.foldAll().

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

Template

<Tree :value="item_groups_tree" ref="tree">
...
</Tree>

In script

this.$refs.tree.foldAll()

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Thanks again. But I am sorry it's didn't work for me :(

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

can you show the code?

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Here is my code:

Templaste:

<Tree :value="item_groups_tree" ref="tree">
    <span slot-scope="{node, index, path, tree}">
      <b @click="tree.toggleFold(node, path)">
        {{node.$folded ? '+' : '-'}}
      </b>
        {{node.Name + ' ('+node.SystemKey+')'}}
    </span>
</Tree>

Script:

mounted() {

    //this.$refs.tree.foldAll();

    if (this.foldAllAfterMounted) {
        this.$refs.tree.foldAll();
    }
}

I am also tried to call this.$refs.tree.foldAll(); after init item_groups_tree data variable.

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024
mounted() {
  this.$refs.tree.foldAll();
}

is it works?

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Sorry it is not working.
image

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

when is item_groups_tree ready? tree.foldAll() will walk all nodes and set $folded of each node to true. so the data must be ready before foldAll called.

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

I am also assumed that. I don't understand why it's not working?

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

check App.vue in this: https://codesandbox.io/s/vue-cli-and-he-tree-vue-example-k2d11
foldAllAfterMounted works well

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Hi,

Thanks so much for your solutions. I flow like your component design TreeView. When I call tree.foldAll() inside of the overrideSlotDefault() method then It folds all the tree node.

But the problem is when I return this content it's print as text like the below image.

overrideSlotDefault({ node, index, path, tree }, original) {
    tree.foldAll();
    let html =
        `<button class="mrs fold-btn" @click="${tree.toggleFold(node, path)}">${node.$folded ? "+" : "-"} </button> ${node.Name}
       `;
    return html;
    //return ((node.$folded ? "+" : "-") + node.Name);
}

image

If I return this ((node.$folded ? "+" : "-") + node.Name) then the view like this:
image

But If I try to use your implementation from here:( https://codesandbox.io/s/vue-cli-and-he-tree-vue-example-k2d11) then I got an error. I am using Vue inside Laravel app.
Here is the error image:
image

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

tree.foldAll() fold all nodes. So just get the tree and execute after your data ready. such as:

httpGetData().then(data => {
this.myTreeData = data
this.$refs.tree.foldAll()
})

overrideSlotDefault is to custom node render. It should return jsx. It will be often called, so the foldAll shoud not be in it.

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

Sorry, there is a bug.

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Oh, Could you please tell me what I will do now about this matter.

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024
this.myTreeData = data
this.$refs.tree.foldAll()

In this, tree will fold old data because the prop is not updated immediately. But if put this.$refs.tree.foldAll() in nextTick, the DOM will flash once.

So walk new data and set $folded=true

import {walkTreeData} from 'he-tree-vue'

httpGetData().then(data => {
  this.myTreeData = data
  walkTreeData(data, node => {this.$set(node, '$folded', true)})
})

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Sorry, maybe I confused you. I just told that tree.foldAll() only work from overrideSlotDefault() method not from Http get request method.

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

Is your data defined in component or get asynchronously such as by ajax?

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Data getting by asynchronously using ajax.

from he-tree-vue.

phphe avatar phphe commented on May 17, 2024

can you show get data and assignment part?

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Here is my component code: https://paste.ubuntu.com/p/nhfBnyK3N7/
and here is the model axios call method:

    static fetchTree(company_id) {

        return new Promise((resolve, reject) => {

            axios.post('/web-api/e-commerce/itemgroups/tree', {
                companyId: company_id,
            })
                .then(({data}) => {

                    resolve(data);

                })
                .catch(error => {
                    reject(error);
                });

        });
    }

from he-tree-vue.

miyasinarafat avatar miyasinarafat commented on May 17, 2024

Thanks so much. It's working now and I made a mistake with walkTreeData. anyways thanks again for your wonderful support.

from he-tree-vue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.