fix: 修复 input-kv 不支持输入相同 key 问题 Closes #3282 (#3316)

This commit is contained in:
吴多益 2021-12-31 10:19:16 +08:00 committed by GitHub
parent 548f3cccfd
commit 5e969c5ee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,15 +18,22 @@ addSchemaFilter(function (schema: Schema, renderer, props?: any) {
const arr: Array<any> = [];
Object.keys(value).forEach(key => {
const valueType = typeof value[key];
arr.push({
key: key || '',
value:
valueType === 'string' ||
valueType === 'number' ||
valueType === 'boolean'
? value[key]
: JSON.stringify(value[key])
});
if (key.endsWith('___tmp')) {
arr.push({
key: key.replace('___tmp', ''),
value: ''
});
} else {
arr.push({
key: key || '',
value:
valueType === 'string' ||
valueType === 'number' ||
valueType === 'boolean'
? value[key]
: JSON.stringify(value[key])
});
}
});
return arr;
},
@ -41,7 +48,12 @@ addSchemaFilter(function (schema: Schema, renderer, props?: any) {
try {
value = JSON.parse(value);
} catch (e) {}
obj[key] = value;
// 如果先输入了 a 作为 key想输入 aa 的时候会先进入这里,导致无法输入 aa因此当遇到 key 相同的时候加个 ___tmp 后缀
if (key in obj && typeof value === 'undefined') {
obj[key + '___tmp'] = '';
} else {
obj[key] = value;
}
});
return obj;
},