更新checkbox
parent
b754f13e44
commit
013faae5c7
|
@ -144,7 +144,7 @@
|
||||||
import '../icon/index'
|
import '../icon/index'
|
||||||
import $ from '../utils'
|
import $ from '../utils'
|
||||||
|
|
||||||
export default class CheckboxItem {
|
export default class Checkbox {
|
||||||
props = {
|
props = {
|
||||||
color: '',
|
color: '',
|
||||||
value: '',
|
value: '',
|
||||||
|
@ -162,7 +162,7 @@ export default class CheckboxItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
_checkGroup() {
|
_checkGroup() {
|
||||||
this._isInGroup = this.parentNode.tagName === 'WC-CHECKBOX'
|
this._isInGroup = this.parentNode.tagName === 'WC-CHECKBOX-GROUP'
|
||||||
if (this._isInGroup && this.parentNode.root) {
|
if (this._isInGroup && this.parentNode.root) {
|
||||||
if (this.parentNode.value.includes(this.value)) {
|
if (this.parentNode.value.includes(this.value)) {
|
||||||
this.checked = true
|
this.checked = true
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
import $ from '../utils'
|
import $ from '../utils'
|
||||||
import './checkbox-item'
|
import './checkbox-item'
|
||||||
|
|
||||||
export default class Checkbox {
|
export default class CheckboxGroup {
|
||||||
props = {
|
props = {
|
||||||
value: []
|
value: []
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ export default class Checkbox {
|
||||||
|
|
||||||
_updateChildrenStat() {
|
_updateChildrenStat() {
|
||||||
Array.from(this.children).forEach(it => {
|
Array.from(this.children).forEach(it => {
|
||||||
if (it.tagName === 'WC-CHECKBOX-ITEM' && it.root) {
|
if (it.tagName === 'WC-CHECKBOX' && it.root) {
|
||||||
if (this.value.includes(it.value)) {
|
if (this.value.includes(it.value)) {
|
||||||
it.checked = true
|
it.checked = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -38,10 +38,11 @@ export default class Checkbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
set value(val) {
|
set value(val) {
|
||||||
|
console.log(this, val, this.props.value, val === this.props.value)
|
||||||
if (val === this.props.value) {
|
if (val === this.props.value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.props.value = val
|
this.props.value = [...val]
|
||||||
this._updateChildrenStat()
|
this._updateChildrenStat()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ export default class Checkbox {
|
||||||
tmp.splice(idx, 1)
|
tmp.splice(idx, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.props.value = tmp
|
this.value = tmp
|
||||||
this.dispatchEvent(new CustomEvent('input'))
|
this.dispatchEvent(new CustomEvent('input'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -70,6 +71,7 @@ export default class Checkbox {
|
||||||
watch() {
|
watch() {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'value':
|
case 'value':
|
||||||
|
console.log(val)
|
||||||
if (val) {
|
if (val) {
|
||||||
this.value = val.split(/,\s*?/)
|
this.value = val.split(/,\s*?/)
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue