diff --git a/src/views/tree/TreeDoc.vue b/src/views/tree/TreeDoc.vue index 97b1811c7..745c82247 100644 --- a/src/views/tree/TreeDoc.vue +++ b/src/views/tree/TreeDoc.vue @@ -112,36 +112,73 @@ import Tree from 'primevue/tree'; - + View on GitHub +import NodeService from '../../service/NodeService'; + export default { - data() { - return { - value: null - } - } + data() { + return { + nodes: null, + expandedKeys: {} + } + }, + nodeService: null, + created() { + this.nodeService = new NodeService(); + }, + mounted() { + this.nodeService.getTreeNodes().then(data => this.nodes = data); + }, + methods: { + expandAll() { + for (let node of this.nodes) { + this.expandNode(node); + } + + this.expandedKeys = {...this.expandedKeys}; + }, + collapseAll() { + this.expandedKeys = {}; + }, + expandNode(node) { + this.expandedKeys[node.key] = true; + if (node.children && node.children.length) { + for (let child of node.children) { + this.expandNode(child); + } + } + } + } } diff --git a/src/views/tree/TreeFilterDemo.vue b/src/views/tree/TreeFilterDemo.vue index f9915db39..44307dd7e 100644 --- a/src/views/tree/TreeFilterDemo.vue +++ b/src/views/tree/TreeFilterDemo.vue @@ -17,9 +17,64 @@ - +
+ + + + + + + +import NodeService from '../../service/NodeService'; + +export default { + data() { + return { + nodes: null, + expandedKeys: {} + } + }, + nodeService: null, + created() { + this.nodeService = new NodeService(); + }, + mounted() { + this.nodeService.getTreeNodes().then(data => this.nodes = data); + }, + methods: { + expandAll() { + for (let node of this.nodes) { + this.expandNode(node); + } + + this.expandedKeys = {...this.expandedKeys}; + }, + collapseAll() { + this.expandedKeys = {}; + }, + expandNode(node) { + this.expandedKeys[node.key] = true; + if (node.children << node.children.length) { + for (let child of node.children) { + this.expandNode(child); + } + } + } + } +} + + + +
+