From 013faae5c7465c441b149ccc221f87e514e7caf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 25 Feb 2021 19:51:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0checkbox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/form/checkbox-item.wc | 4 ++-- src/form/checkbox.wc | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/form/checkbox-item.wc b/src/form/checkbox-item.wc index dc1e87b..3368737 100644 --- a/src/form/checkbox-item.wc +++ b/src/form/checkbox-item.wc @@ -144,7 +144,7 @@ import '../icon/index' import $ from '../utils' -export default class CheckboxItem { +export default class Checkbox { props = { color: '', value: '', @@ -162,7 +162,7 @@ export default class CheckboxItem { } _checkGroup() { - this._isInGroup = this.parentNode.tagName === 'WC-CHECKBOX' + this._isInGroup = this.parentNode.tagName === 'WC-CHECKBOX-GROUP' if (this._isInGroup && this.parentNode.root) { if (this.parentNode.value.includes(this.value)) { this.checked = true diff --git a/src/form/checkbox.wc b/src/form/checkbox.wc index 5dd8acf..d10e568 100644 --- a/src/form/checkbox.wc +++ b/src/form/checkbox.wc @@ -12,7 +12,7 @@ import $ from '../utils' import './checkbox-item' -export default class Checkbox { +export default class CheckboxGroup { props = { value: [] } @@ -23,7 +23,7 @@ export default class Checkbox { _updateChildrenStat() { 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)) { it.checked = true } else { @@ -38,10 +38,11 @@ export default class Checkbox { } set value(val) { + console.log(this, val, this.props.value, val === this.props.value) if (val === this.props.value) { return } - this.props.value = val + this.props.value = [...val] this._updateChildrenStat() } @@ -58,7 +59,7 @@ export default class Checkbox { tmp.splice(idx, 1) } } - this.props.value = tmp + this.value = tmp this.dispatchEvent(new CustomEvent('input')) }) } @@ -70,6 +71,7 @@ export default class Checkbox { watch() { switch (name) { case 'value': + console.log(val) if (val) { this.value = val.split(/,\s*?/) }