fix: duplicate value
This commit is contained in:
parent
ec780f2018
commit
eb88cc4269
1 changed files with 12 additions and 9 deletions
|
|
@ -70,22 +70,25 @@ export const createSelect = <T extends Record<string, any>>(
|
|||
|
||||
if (!currentValue) return;
|
||||
|
||||
const option = selectOptions.value.find(
|
||||
(v) => v[valueField] === currentValue,
|
||||
);
|
||||
|
||||
if (option) {
|
||||
valueOption.value = option;
|
||||
return;
|
||||
}
|
||||
if (valueOption.value && valueOption.value[valueField] === currentValue) {
|
||||
return selectOptions.value.unshift(valueOption.value);
|
||||
selectOptions.value.unshift(valueOption.value);
|
||||
selectOptions.value = selectOptions.value.filter((curr, idx, arr) => {
|
||||
return (
|
||||
arr.findIndex((item) => item[valueField] === curr[valueField]) === idx
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const ret = await getByValue(currentValue);
|
||||
|
||||
if (ret) {
|
||||
selectOptions.value.unshift(ret);
|
||||
selectOptions.value = selectOptions.value.filter((curr, idx, arr) => {
|
||||
return (
|
||||
arr.findIndex((item) => item[valueField] === curr[valueField]) === idx
|
||||
);
|
||||
});
|
||||
valueOption.value = ret;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue