Commit 53754a31853f9e2c90ef493f3fb3bfb96bb6e17b

Authored by 梁灏
1 parent 3c145e6f

fixed #468

rebuild Tree component
examples/routers/tree.vue
1 1 <template>
2   - <Tree :data="baseData" @on-select-change="handleSelectChange" show-checkbox></Tree>
  2 + <Tree :data="baseData" @on-check-change="handleSelectChange" show-checkbox></Tree>
3 3 </template>
4 4 <script>
5 5 export default {
... ...
src/components/tree/node.vue
... ... @@ -58,8 +58,7 @@
58 58 data () {
59 59 return {
60 60 prefixCls: prefixCls,
61   - indeterminate: false,
62   - checked: false
  61 + indeterminate: false
63 62 };
64 63 },
65 64 computed: {
... ... @@ -120,6 +119,7 @@
120 119 }
121 120 this.data.checked = checked;
122 121 this.dispatch('Tree', 'checked');
  122 + this.dispatch('Tree', 'on-checked');
123 123 },
124 124 setIndeterminate () {
125 125 this.indeterminate = this.data.checked ? false : findComponentsDownward(this, 'TreeNode').some(node => node.data.checked);
... ... @@ -131,6 +131,7 @@
131 131 },
132 132 mounted () {
133 133 this.$on('indeterminate', () => {
  134 + this.broadcast('TreeNode', 'indeterminate');
134 135 this.setIndeterminate();
135 136 });
136 137 }
... ...
src/components/tree/tree.vue
... ... @@ -54,6 +54,10 @@
54 54 const nodes = findComponentsDownward(this, 'TreeNode');
55 55 return nodes.filter(node => node.data.selected).map(node => node.data);
56 56 },
  57 + getCheckedNodes () {
  58 + const nodes = findComponentsDownward(this, 'TreeNode');
  59 + return nodes.filter(node => node.data.checked).map(node => node.data);
  60 + },
57 61 updateData (isInit = true) {
58 62 // init checked status
59 63 function reverseChecked(data) {
... ... @@ -105,6 +109,9 @@
105 109 this.$on('checked', () => {
106 110 this.updateData(false);
107 111 });
  112 + this.$on('on-checked', () => {
  113 + this.$emit('on-check-change', this.getCheckedNodes());
  114 + });
108 115 }
109 116 };
110 117 </script>
111 118 \ No newline at end of file
... ...