From 8aacd4361e9a48d889b69e8454f639fd4597dc82 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Wed, 28 Jun 2023 19:27:46 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4=20dataMapping=20?= =?UTF-8?q?=E4=B8=AD=20'&'=20=E7=89=B9=E6=AE=8A=20key=20=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20=E5=A7=8B=E7=BB=88=E4=BC=98=E5=85=88=E5=A4=84?= =?UTF-8?q?=E7=90=86=20Close:=20#7247=20(#7264)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/utils/dataMapping.ts | 27 +++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/amis-core/src/utils/dataMapping.ts b/packages/amis-core/src/utils/dataMapping.ts index b50e86321..64b2f1e25 100644 --- a/packages/amis-core/src/utils/dataMapping.ts +++ b/packages/amis-core/src/utils/dataMapping.ts @@ -99,19 +99,21 @@ export function dataMapping( ); } } else { - Object.keys(to).forEach(key => { - const value = to[key]; - let keys: Array; + const objectKeys = Object.keys(to); + // 如果存在 '&' 作为 key,则特殊处理 + // 就是无论这个 key 的位置在什么地方始终都是当放在最前面 + const idx = objectKeys.indexOf('&'); + if (~idx) { + const value = to['&']; + objectKeys.splice(idx, 1); - if (typeof ignoreFunction === 'function' && ignoreFunction(key, value)) { - // 如果被ignore,不做数据映射处理。 - setVariable(ret, key, value, convertKeyToPath); - } else if (key === '&' && value === '$$') { + if (value === '$$') { ret = { ...ret, ...from }; - } else if (key === '&') { + } else { + let keys: Array; const v = isPlainObject(value) && (keys = Object.keys(value)) && @@ -142,6 +144,15 @@ export function dataMapping( ...v }; } + } + } + + objectKeys.forEach(key => { + const value = to[key]; + + if (typeof ignoreFunction === 'function' && ignoreFunction(key, value)) { + // 如果被ignore,不做数据映射处理。 + setVariable(ret, key, value, convertKeyToPath); } else if (value === '$$') { setVariable(ret, key, from, convertKeyToPath); } else if (value && value[0] === '$') {