Commit 53754a31853f9e2c90ef493f3fb3bfb96bb6e17b
1 parent
3c145e6f
fixed #468
rebuild Tree component
Showing
3 changed files
with
11 additions
and
3 deletions
Show diff stats
examples/routers/tree.vue
src/components/tree/node.vue
| @@ -58,8 +58,7 @@ | @@ -58,8 +58,7 @@ | ||
| 58 | data () { | 58 | data () { |
| 59 | return { | 59 | return { |
| 60 | prefixCls: prefixCls, | 60 | prefixCls: prefixCls, |
| 61 | - indeterminate: false, | ||
| 62 | - checked: false | 61 | + indeterminate: false |
| 63 | }; | 62 | }; |
| 64 | }, | 63 | }, |
| 65 | computed: { | 64 | computed: { |
| @@ -120,6 +119,7 @@ | @@ -120,6 +119,7 @@ | ||
| 120 | } | 119 | } |
| 121 | this.data.checked = checked; | 120 | this.data.checked = checked; |
| 122 | this.dispatch('Tree', 'checked'); | 121 | this.dispatch('Tree', 'checked'); |
| 122 | + this.dispatch('Tree', 'on-checked'); | ||
| 123 | }, | 123 | }, |
| 124 | setIndeterminate () { | 124 | setIndeterminate () { |
| 125 | this.indeterminate = this.data.checked ? false : findComponentsDownward(this, 'TreeNode').some(node => node.data.checked); | 125 | this.indeterminate = this.data.checked ? false : findComponentsDownward(this, 'TreeNode').some(node => node.data.checked); |
| @@ -131,6 +131,7 @@ | @@ -131,6 +131,7 @@ | ||
| 131 | }, | 131 | }, |
| 132 | mounted () { | 132 | mounted () { |
| 133 | this.$on('indeterminate', () => { | 133 | this.$on('indeterminate', () => { |
| 134 | + this.broadcast('TreeNode', 'indeterminate'); | ||
| 134 | this.setIndeterminate(); | 135 | this.setIndeterminate(); |
| 135 | }); | 136 | }); |
| 136 | } | 137 | } |
src/components/tree/tree.vue
| @@ -54,6 +54,10 @@ | @@ -54,6 +54,10 @@ | ||
| 54 | const nodes = findComponentsDownward(this, 'TreeNode'); | 54 | const nodes = findComponentsDownward(this, 'TreeNode'); |
| 55 | return nodes.filter(node => node.data.selected).map(node => node.data); | 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 | updateData (isInit = true) { | 61 | updateData (isInit = true) { |
| 58 | // init checked status | 62 | // init checked status |
| 59 | function reverseChecked(data) { | 63 | function reverseChecked(data) { |
| @@ -105,6 +109,9 @@ | @@ -105,6 +109,9 @@ | ||
| 105 | this.$on('checked', () => { | 109 | this.$on('checked', () => { |
| 106 | this.updateData(false); | 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 | </script> | 117 | </script> |
| 111 | \ No newline at end of file | 118 | \ No newline at end of file |