|
2 | 2 | 'use strict';
|
3 | 3 | var VueTreeItem = Vue.extend({
|
4 | 4 | template: '<li :class="{parent_li: node.isParent}">' +
|
5 |
| - '<i v-if="node.isParent" v-on:click="click(node)" class="fa icon-open-state" :class=\'{"fa-plus-square-o": !node.isOpen, "fa-minus-square-o": node.isOpen}\'></i>' + |
| 5 | + '<i v-if="node.isParent" v-on:click="toggle(node)" class="fa icon-open-state" :class=\'{"fa-plus-square-o": !node.isOpen, "fa-minus-square-o": node.isOpen}\'></i>' + |
6 | 6 | '<span :title="node.title">' +
|
7 | 7 | '<i v-if="showIcon(node)" :class="nodeClass(node)"></i> {{node.name}}</span>' +
|
8 | 8 | '<a v-for="btn in node.buttons" class="ml5" href="javascript:" :title="btn.title" v-on:click="btnClick(btn, node)"><i :class="btn.icon"></i></a>' +
|
9 |
| - '<ul v-if="node.children && node.children.length" v-show="node.isOpen">' + |
| 9 | + '<ul v-show="node.isOpen">' + |
| 10 | + '<li v-show="node.showLoading && node._loading"><i class="fa fa-spinner fa-pulse"></i></li>' + |
10 | 11 | '<vue-tree-item v-for="item in node.children" :node="item"></vue-tree-item>' +
|
11 | 12 | '</ul>' +
|
12 | 13 | '</li>',
|
|
26 | 27 | return node.closedIcon || node.icon;
|
27 | 28 | }
|
28 | 29 | },
|
29 |
| - click: function (node) { |
30 |
| - node.isOpen = !node.isOpen; |
| 30 | + toggle: function (node) { |
| 31 | + if (node.hasOwnProperty('isOpen')) { |
| 32 | + node.isOpen = !node.isOpen; |
| 33 | + } else { |
| 34 | + Vue.set(node, 'isOpen', true); |
| 35 | + } |
31 | 36 | },
|
32 | 37 | btnClick: function (btn, node) {
|
33 | 38 | if (typeof btn.click === 'function') {
|
34 | 39 | btn.click(node);
|
35 | 40 | }
|
36 | 41 | }
|
| 42 | + }, |
| 43 | + watch: { |
| 44 | + 'node.isOpen': function (val) { |
| 45 | + if (!this.node.hasOwnProperty('_loading')) { |
| 46 | + Vue.set(this.node, '_loading', false); |
| 47 | + } |
| 48 | + if (val) { |
| 49 | + if (typeof this.node.onOpened === 'function') { |
| 50 | + this.node.onOpened(this.node); |
| 51 | + } |
| 52 | + } else { |
| 53 | + if (typeof this.node.onClosed === 'function') { |
| 54 | + this.node.onClosed(this.node); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
37 | 58 | }
|
38 | 59 | });
|
39 | 60 | Vue.component('vue-tree-item', VueTreeItem);
|
|
0 commit comments