From 19c61207463b376d7342ed065583c9fa84f04e00 Mon Sep 17 00:00:00 2001 From: lin-mt Date: Fri, 21 Feb 2025 22:37:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=9A=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=90=8D=E7=A7=B0=E6=98=AF=E7=AC=AC=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=BF=85=E9=80=89=E5=B1=9E=E6=80=A7=E6=97=B6=EF=BC=8C=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1=E5=BF=85=E9=80=89=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JsonSchemaEditor/index.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/JsonSchemaEditor/index.tsx b/src/JsonSchemaEditor/index.tsx index d017e91..e188a1a 100644 --- a/src/JsonSchemaEditor/index.tsx +++ b/src/JsonSchemaEditor/index.tsx @@ -130,10 +130,12 @@ const JsonSchemaEditor = forwardRef( parent[lastKey] = Object.fromEntries( Object.entries(current).map(([key, value]) => { if (key === oldKey) { - const requiredIndex = parent['required']?.indexOf(oldKey); - if (requiredIndex && requiredIndex !== -1) { - parent['required'].splice(requiredIndex, 1); - parent['required'].push(newKey); + const parentRequired = parent['required']; + if (parentRequired) { + const requiredIndex = parentRequired.indexOf(oldKey); + if (requiredIndex >= 0) { + parentRequired.splice(requiredIndex, 1, newKey); + } } return [newKey, value]; }