mirror of https://github.com/ElemeFE/element
Select: fix async bug/fix object-typed value init issue (#1540)
parent
ea56806de7
commit
6e618b4c6d
|
@ -256,7 +256,7 @@
|
||||||
this.resetHoverIndex();
|
this.resetHoverIndex();
|
||||||
if (!this.multiple) {
|
if (!this.multiple) {
|
||||||
this.getOverflows();
|
this.getOverflows();
|
||||||
if (this.selected && this.selected.value) {
|
if (this.selected) {
|
||||||
this.selectedLabel = this.selected.currentLabel;
|
this.selectedLabel = this.selected.currentLabel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,6 +286,10 @@
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
this.resetInputHeight();
|
this.resetInputHeight();
|
||||||
}
|
}
|
||||||
|
let inputs = this.$el.querySelectorAll('input');
|
||||||
|
if ([].indexOf.call(inputs, document.activeElement) === -1) {
|
||||||
|
this.selected = this.getSelected();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -325,26 +329,31 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getOption(value) {
|
||||||
|
const option = this.options.filter(option => option.value === value)[0];
|
||||||
|
if (option) return option;
|
||||||
|
const label = typeof value === 'string' || typeof value === 'number'
|
||||||
|
? value : '';
|
||||||
|
let newOption = {
|
||||||
|
value: value,
|
||||||
|
currentLabel: label
|
||||||
|
};
|
||||||
|
if (this.multiple) {
|
||||||
|
newOption.hitState = false;
|
||||||
|
}
|
||||||
|
return newOption;
|
||||||
|
},
|
||||||
|
|
||||||
getSelected() {
|
getSelected() {
|
||||||
if (!this.multiple) {
|
if (!this.multiple) {
|
||||||
let option = this.options.filter(option => option.value === this.value)[0] ||
|
let option = this.getOption(this.value);
|
||||||
{ value: this.value, currentLabel: this.value };
|
|
||||||
this.selectedLabel = option.currentLabel;
|
this.selectedLabel = option.currentLabel;
|
||||||
return option;
|
return option;
|
||||||
}
|
}
|
||||||
let result = [];
|
let result = [];
|
||||||
if (Array.isArray(this.value)) {
|
if (Array.isArray(this.value)) {
|
||||||
this.value.forEach(value => {
|
this.value.forEach(value => {
|
||||||
let option = this.options.filter(option => option.value === value)[0];
|
result.push(this.getOption(value));
|
||||||
if (option) {
|
|
||||||
result.push(option);
|
|
||||||
} else {
|
|
||||||
result.push({
|
|
||||||
value: this.value,
|
|
||||||
currentLabel: value,
|
|
||||||
hitState: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -555,7 +564,7 @@
|
||||||
if (this.multiple && !Array.isArray(this.value)) {
|
if (this.multiple && !Array.isArray(this.value)) {
|
||||||
this.$emit('input', []);
|
this.$emit('input', []);
|
||||||
}
|
}
|
||||||
if (!this.multiple && (!this.value || Array.isArray(this.value))) {
|
if (!this.multiple && Array.isArray(this.value)) {
|
||||||
this.$emit('input', '');
|
this.$emit('input', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue