fix: data-mapping, fixed no data source (#1315)

Reviewed-on: daoyoucloud/tachybase#1315
Co-authored-by: bai.zixv <bai.zixv@foxmail.com>
Co-committed-by: bai.zixv <bai.zixv@foxmail.com>
This commit is contained in:
bai.zixv 2024-07-15 11:51:54 +08:00 committed by sealday
parent 0a11007dea
commit d026303395

View File

@ -12,19 +12,29 @@ export class DataMappingInstruction extends Instruction {
const { sourceArray, type, code = '', model } = node.config; const { sourceArray, type, code = '', model } = node.config;
// 1. 获取数据源 // 1. 获取数据源
let data = {}; let data = {};
if (sourceArray.length > 1) {
// 多个数据源, 进行合并 switch (sourceArray.length) {
data = sourceArray.reduce( case 0: {
(cookedData, { keyName, sourcePath }) => ({ // 无数据源,使用默认值
...cookedData, data = {};
[keyName]: processor.getParsedValue(sourcePath, node.id), break;
}), }
{}, case 1: {
); // 单数据源, 平铺为单对象; 忽略keyName
} else { const source = sourceArray[0]['sourcePath'];
// 单数据源, 平铺为单对象 data = processor.getParsedValue(source, node.id);
const source = sourceArray[0]['sourcePath']; break;
data = processor.getParsedValue(source, node.id); }
default: {
// 多个数据源, 进行合并
data = sourceArray.reduce(
(cookedData, { keyName, sourcePath }) => ({
...cookedData,
[keyName]: processor.getParsedValue(sourcePath, node.id),
}),
{},
);
}
} }
try { try {