From 92d08b0ae49cea92f5812ccd535bbc1c61043b18 Mon Sep 17 00:00:00 2001 From: sansiro Date: Thu, 15 Sep 2022 19:28:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20inputText=20autoComplete=20=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E5=86=85=E5=AE=B9=E5=AF=BC=E8=87=B4=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98=20(#5272)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: inputText autoComplete 输入内容导致选项重复问题 * 修改 --- packages/amis-core/src/utils/optionValueCompare.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/amis-core/src/utils/optionValueCompare.ts b/packages/amis-core/src/utils/optionValueCompare.ts index 24e1e1adc..04369373e 100644 --- a/packages/amis-core/src/utils/optionValueCompare.ts +++ b/packages/amis-core/src/utils/optionValueCompare.ts @@ -1,14 +1,20 @@ import {OptionValue, Option} from '../types'; import {isObject} from './helper'; +import {isEqual} from 'lodash'; export function matchOptionValue( a: OptionValue, b: Option, valueField: string = 'value' ) { - return isObject(a) - ? a === b[valueField || 'value'] - : String(b[valueField || 'value']) === String(a); + // a 可能为 Option, 此时需要取其value + const aValue = + isObject(a) && a && (a as Option).hasOwnProperty(valueField) + ? (a as Option)[valueField] + : a; + return isObject(aValue) + ? isEqual(aValue, b[valueField || 'value']) + : String(b[valueField || 'value']) === String(aValue); } export function optionValueCompare(