Comments (25)
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.
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.
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.
from he-tree-vue.
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.
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.
Template
<Tree :value="item_groups_tree" ref="tree">
...
</Tree>
In script
this.$refs.tree.foldAll()
from he-tree-vue.
Thanks again. But I am sorry it's didn't work for me :(
from he-tree-vue.
can you show the code?
from he-tree-vue.
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.
mounted() {
this.$refs.tree.foldAll();
}
is it works?
from he-tree-vue.
from he-tree-vue.
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.
I am also assumed that. I don't understand why it's not working?
from he-tree-vue.
check App.vue in this: https://codesandbox.io/s/vue-cli-and-he-tree-vue-example-k2d11
foldAllAfterMounted works well
from he-tree-vue.
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);
}
If I return this ((node.$folded ? "+" : "-") + node.Name)
then the view like this:
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:
from he-tree-vue.
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.
Sorry, there is a bug.
from he-tree-vue.
Oh, Could you please tell me what I will do now about this matter.
from he-tree-vue.
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.
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.
Is your data defined in component or get asynchronously such as by ajax?
from he-tree-vue.
Data getting by asynchronously using ajax.
from he-tree-vue.
can you show get data and assignment part?
from he-tree-vue.
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.
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)
- Drag items outside the tree HOT 1
- The events do not work for Vue3 HOT 1
- Wrong index of dragged node when drop it after another node HOT 1
- Event node-folded-changed not emited on fold node HOT 1
- How to add specific data to nested children in he-tree-vue HOT 1
- [vite dev] Error loading external "node_modules/tslib/tslib.es6.js". HOT 1
- with vite : @babel does not provide an export named 'default'
- How to know value from targetPath when ondragend HOT 7
- how to delete a node using by id (unique) HOT 8
- Is this library deprecated HOT 1
- Expand all ancestors HOT 5
- Problem use he-tree-vue HOT 5
- Droppable false not working HOT 2
- Demo3Fold.vue not working in vue 3 HOT 1
- display the treeData structure in reverse order HOT 1
- How to disable placeholder display? HOT 1
- Get Parent Node Of the dropped Node HOT 2
- Limit the depth of tree HOT 3
- Unfold to path HOT 7
- Create an emit for nodecreated? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from he-tree-vue.