(fix)修复star-select无法设置选中值的故障
This commit is contained in:
parent
621f5e6981
commit
3141e18bad
|
@ -64,7 +64,11 @@ export class StarSelect extends StarBaseElement {
|
|||
|
||||
// }
|
||||
|
||||
protected firstUpdated(): void {
|
||||
protected firstUpdated() {
|
||||
this.initialOptionsSlot()
|
||||
}
|
||||
|
||||
protected initialOptionsSlot() {
|
||||
// 1. 为 radio 标签,或是有实现类 radio 标签行为的标签
|
||||
// 如 <star-li type="radio">,<star-card type="radio">
|
||||
// 2. 不满足1的标签将被删除
|
||||
|
@ -102,7 +106,7 @@ export class StarSelect extends StarBaseElement {
|
|||
for (const [index, option] of this.optionsSlot.entries()) {
|
||||
if (this.selected !== undefined) {
|
||||
if (this.multiple === false) {
|
||||
if (this.selected === option.value) {
|
||||
if (String(this.selected) === option.value) {
|
||||
this.label = option.label
|
||||
option.checked = true
|
||||
break
|
||||
|
@ -132,7 +136,7 @@ export class StarSelect extends StarBaseElement {
|
|||
/**
|
||||
* 事件来源:star-radio-group 上的change自定义事件
|
||||
*/
|
||||
_onselect(e: Event) {
|
||||
protected _onselect(e: Event) {
|
||||
const target = e.target as StarRadioGroup
|
||||
if (this.selected !== target.selected) {
|
||||
this.selected = target.getSelected()
|
||||
|
@ -141,11 +145,16 @@ export class StarSelect extends StarBaseElement {
|
|||
}
|
||||
}
|
||||
|
||||
public setSelected(str: string | number) {
|
||||
this.selected = String(str)
|
||||
this.initialOptionsSlot()
|
||||
}
|
||||
|
||||
/**
|
||||
* 当自身被点击时,打开 <select-dialog>,将 options 租借给它。
|
||||
* 完成调用后,<select-dialog> 再将 options 归还。
|
||||
*/
|
||||
_onclick(_: Event) {
|
||||
protected _onclick(_: Event) {
|
||||
const starAlertDialog = new StarSelectDialog({
|
||||
title: this.title || '测试',
|
||||
type: 'select',
|
||||
|
|
Loading…
Reference in New Issue