mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
Merge pull request #8759 from 2betop/fix-quickEdit-name-path
fix: 修复 quickEdit inline 模式 name 为带层级时发送的数据不符合预期 Close: #8756
This commit is contained in:
commit
ee6fc42450
@ -127,8 +127,13 @@ export function setVariable(
|
||||
|
||||
const parts = convertKeyToPath !== false ? keyToPath(key) : [key];
|
||||
const last = parts.pop() as string;
|
||||
const stack: Array<{
|
||||
host: Record<string, any>;
|
||||
key: string;
|
||||
}> = [];
|
||||
|
||||
while (parts.length) {
|
||||
let host = data;
|
||||
let key = parts.shift() as string;
|
||||
if (isPlainObject(data[key])) {
|
||||
data = data[key] = {
|
||||
@ -143,9 +148,25 @@ export function setVariable(
|
||||
data[key] = {};
|
||||
data = data[key];
|
||||
} else {
|
||||
// 如果是数字,那么就是数组
|
||||
if (/^\d+$/.test(key) && stack.length) {
|
||||
const prev = stack[stack.length - 1];
|
||||
if (
|
||||
!Array.isArray(prev.host[prev.key]) &&
|
||||
!Object.keys(prev.host[prev.key]).length
|
||||
) {
|
||||
host = data = prev.host[prev.key] = [];
|
||||
}
|
||||
}
|
||||
|
||||
data[key] = {};
|
||||
data = data[key];
|
||||
}
|
||||
|
||||
stack.push({
|
||||
host,
|
||||
key
|
||||
});
|
||||
}
|
||||
|
||||
data[last] = value;
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import {findDOMNode} from 'react-dom';
|
||||
import {RendererProps, getRendererByName, noop} from 'amis-core';
|
||||
import {RendererProps, getRendererByName, noop, setVariable} from 'amis-core';
|
||||
import hoistNonReactStatic from 'hoist-non-react-statics';
|
||||
import {ActionObject} from 'amis-core';
|
||||
import keycode from 'keycode';
|
||||
@ -353,8 +353,10 @@ export const HocQuickEdit =
|
||||
handleFormItemChange(value: any) {
|
||||
const {onQuickChange, quickEdit, name} = this.props;
|
||||
|
||||
const data = {};
|
||||
setVariable(data, name!, value);
|
||||
onQuickChange(
|
||||
{[name!]: value},
|
||||
data,
|
||||
(quickEdit as QuickEditConfig).saveImmediately,
|
||||
false,
|
||||
quickEdit as QuickEditConfig
|
||||
|
Loading…
Reference in New Issue
Block a user