Skip to content

Commit 14771fa

Browse files
committed
fixed #44 [1.6.1] multiple select error.
1 parent 2c6cd04 commit 14771fa

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

example/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
</vue-json-pretty>
134134
</div>
135135
</div>
136-
<a style="position: fixed; right: 0; top: 0;" href="https://github.com/leezng/el-form-renderer" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>
136+
<a style="position: fixed; right: 0; top: 0;" href="https://github.com/leezng/vue-json-pretty" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"></a>
137137
</div>
138138
</template>
139139

src/components/app.vue

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
'is-highlight-selected': isSelected && highlightSelectedNode,
1010
'is-mouseover': isMouseover
1111
}"
12-
@click="handleClick($event, 'tree')"
12+
@click="handleClick"
1313
@mouseover.stop="handleMouseover"
1414
@mouseout.stop="handleMouseout">
1515
<template v-if="showSelectController && selectable">
16-
<vue-checkbox v-if="isMultiple" v-model="currentCheckboxVal" @change="handleClick($event, 'checkbox')"></vue-checkbox>
17-
<vue-radio v-else-if="isSingle" v-model="model" @change="handleClick($event, 'radio')" :path="path"></vue-radio>
16+
<vue-checkbox v-if="isMultiple" v-model="currentCheckboxVal" @change="handleValueChange('checkbox')"></vue-checkbox>
17+
<vue-radio v-else-if="isSingle" v-model="model" @change="handleValueChange('radio')" :path="path"></vue-radio>
1818
</template>
1919

2020
<template v-if="Array.isArray(data) || isObject(data)">
@@ -237,20 +237,8 @@
237237
}
238238
},
239239
methods: {
240-
/**
241-
* emit click event
242-
* @param {string} emitType tree/checkbox/radio
243-
*/
244-
handleClick (e, emitType = '') {
245-
// Event can not be stopPropagation, because user may be listening the click event.
246-
// So use _uid to simulated.
247-
if (e._uid && e._uid !== this._uid) return
248-
e._uid = this._uid
249-
250-
this.$emit('click', this.path, this.data)
251-
if (!this.selectable) return
252-
253-
if (this.isMultiple && (emitType === 'checkbox' || (this.selectOnClickNode && emitType === 'tree'))) {
240+
handleValueChange (emitType) {
241+
if (this.isMultiple && (emitType === 'checkbox' || emitType === 'tree')) {
254242
// handle multiple
255243
const index = this.model.findIndex(item => item === this.path)
256244
const oldVal = [...this.model]
@@ -264,7 +252,7 @@
264252
this.currentCheckboxVal = !this.currentCheckboxVal
265253
}
266254
this.$emit('change', this.model, oldVal)
267-
} else if (this.isSingle && (emitType === 'radio' || (this.selectOnClickNode && emitType === 'tree'))) {
255+
} else if (this.isSingle && (emitType === 'radio' || emitType === 'tree')) {
268256
// handle single
269257
if (this.model !== this.path) {
270258
const oldVal = this.model
@@ -275,6 +263,22 @@
275263
}
276264
},
277265
266+
/**
267+
* emit click event
268+
* @param {string} emitType tree/checkbox/radio
269+
*/
270+
handleClick (e) {
271+
// Event can not be stopPropagation, because user may be listening the click event.
272+
// So use _uid to simulated.
273+
if (e._uid && e._uid !== this._uid) return
274+
e._uid = this._uid
275+
276+
this.$emit('click', this.path, this.data)
277+
if (this.selectable && this.selectOnClickNode) {
278+
this.handleValueChange('tree')
279+
}
280+
},
281+
278282
// handle children's click, and propagation
279283
handleItemClick (path, data) {
280284
this.$emit('click', path, data)

src/components/radio.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
type="radio"
88
v-model="model"
99
:value="currentPath"
10-
@change="test"
10+
@change="change"
1111
@focus="focus = true"
1212
@blur="focus = false">
1313
</label>
@@ -42,7 +42,7 @@
4242
}
4343
},
4444
methods: {
45-
test () {
45+
change () {
4646
this.$emit('change', this.model)
4747
}
4848
}

0 commit comments

Comments
 (0)