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] === '$') {