Merge pull request #3798 from m430/bug-3795
Select patches: fix bug #3795 #3722 修复select异步获取option数据导致,v-model失效等问题
This commit is contained in:
commit
3a3be61a25
2 changed files with 19 additions and 8 deletions
|
@ -58,7 +58,7 @@
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
initialLabel: {
|
initialLabel: {
|
||||||
type: String,
|
type: [String, Number, Array],
|
||||||
},
|
},
|
||||||
values: {
|
values: {
|
||||||
type: Array,
|
type: Array,
|
||||||
|
|
|
@ -230,9 +230,7 @@
|
||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.values.length > 0 && this.selectOptions.length === 0){
|
this.checkUpdateStatus();
|
||||||
this.hasExpectedValue = this.values;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
|
||||||
|
@ -353,7 +351,7 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
let hasDefaultSelected = slotOptions.some(option => this.query === option.key);
|
||||||
for (let option of slotOptions) {
|
for (let option of slotOptions) {
|
||||||
|
|
||||||
const cOptions = option.componentOptions;
|
const cOptions = option.componentOptions;
|
||||||
|
@ -377,8 +375,10 @@
|
||||||
if (cOptions.children.length > 0) selectOptions.push({...option});
|
if (cOptions.children.length > 0) selectOptions.push({...option});
|
||||||
} else {
|
} else {
|
||||||
// ignore option if not passing filter
|
// ignore option if not passing filter
|
||||||
|
if (!hasDefaultSelected) {
|
||||||
const optionPassesFilter = this.filterable ? this.validateOption(cOptions) : option;
|
const optionPassesFilter = this.filterable ? this.validateOption(cOptions) : option;
|
||||||
if (!optionPassesFilter) continue;
|
if (!optionPassesFilter) continue;
|
||||||
|
}
|
||||||
|
|
||||||
optionCounter = optionCounter + 1;
|
optionCounter = optionCounter + 1;
|
||||||
selectOptions.push(this.processOption(option, selectedValues, optionCounter === currentIndex));
|
selectOptions.push(this.processOption(option, selectedValues, optionCounter === currentIndex));
|
||||||
|
@ -426,6 +426,7 @@
|
||||||
const {multiple, value} = this;
|
const {multiple, value} = this;
|
||||||
let initialValue = Array.isArray(value) ? value : [value];
|
let initialValue = Array.isArray(value) ? value : [value];
|
||||||
if (!multiple && (typeof initialValue[0] === 'undefined' || (String(initialValue[0]).trim() === '' && !Number.isFinite(initialValue[0])))) initialValue = [];
|
if (!multiple && (typeof initialValue[0] === 'undefined' || (String(initialValue[0]).trim() === '' && !Number.isFinite(initialValue[0])))) initialValue = [];
|
||||||
|
if (this.remote && !this.multiple && this.value) this.query = value;
|
||||||
return initialValue.filter((item) => {
|
return initialValue.filter((item) => {
|
||||||
return Boolean(item) || item === 0;
|
return Boolean(item) || item === 0;
|
||||||
});
|
});
|
||||||
|
@ -632,12 +633,19 @@
|
||||||
},
|
},
|
||||||
updateSlotOptions(){
|
updateSlotOptions(){
|
||||||
this.slotOptions = this.$slots.default;
|
this.slotOptions = this.$slots.default;
|
||||||
|
},
|
||||||
|
checkUpdateStatus() {
|
||||||
|
if (this.getInitialValue().length > 0 && this.selectOptions.length === 0) {
|
||||||
|
this.hasExpectedValue = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
value(value){
|
value(value){
|
||||||
const {getInitialValue, getOptionData, publicValue} = this;
|
const {getInitialValue, getOptionData, publicValue} = this;
|
||||||
|
|
||||||
|
this.checkUpdateStatus();
|
||||||
|
|
||||||
if (value === '') this.values = [];
|
if (value === '') this.values = [];
|
||||||
else if (JSON.stringify(value) !== JSON.stringify(publicValue)) {
|
else if (JSON.stringify(value) !== JSON.stringify(publicValue)) {
|
||||||
this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean));
|
this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean));
|
||||||
|
@ -716,7 +724,10 @@
|
||||||
this.broadcast('Drop', open ? 'on-update-popper' : 'on-destroy-popper');
|
this.broadcast('Drop', open ? 'on-update-popper' : 'on-destroy-popper');
|
||||||
},
|
},
|
||||||
selectOptions(){
|
selectOptions(){
|
||||||
if (this.hasExpectedValue){
|
if (this.hasExpectedValue && this.selectOptions.length > 0){
|
||||||
|
if (this.values.length === 0) {
|
||||||
|
this.values = this.getInitialValue();
|
||||||
|
}
|
||||||
this.values = this.values.map(this.getOptionData).filter(Boolean);
|
this.values = this.values.map(this.getOptionData).filter(Boolean);
|
||||||
this.hasExpectedValue = false;
|
this.hasExpectedValue = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue