datamapping 支持复杂用法
This commit is contained in:
parent
dc10730381
commit
4e83fcd316
|
@ -108,9 +108,10 @@ export default class FormTable extends React.Component<TableProps, TableState> {
|
|||
|
||||
toAdd.forEach((toAdd:any) => {
|
||||
const idx = findIndex(rows, (item) => item[valueField as string] == toAdd[valueField as string]);
|
||||
if (!~idx) {
|
||||
rows.push(toAdd);
|
||||
if (~idx) {
|
||||
rows.splice(idx, 1);
|
||||
}
|
||||
rows.push(toAdd);
|
||||
});
|
||||
|
||||
onChange(rows);
|
||||
|
|
|
@ -388,7 +388,13 @@ export function dataMapping(to: any, from: PlainObject): any {
|
|||
...from
|
||||
};
|
||||
} else if (key === "&") {
|
||||
const v = resolveMapping(value, from);
|
||||
const v = isPlainObject(value)
|
||||
&& (keys = Object.keys(value))
|
||||
&& keys.length === 1
|
||||
&& from[keys[0].substring(1)]
|
||||
&& Array.isArray(from[keys[0].substring(1)])
|
||||
? from[keys[0].substring(1)].map((raw: object) => dataMapping(value[keys[0]], createObject(from, raw)))
|
||||
: resolveMapping(value, from) ;
|
||||
|
||||
if (Array.isArray(v) || typeof v === "string") {
|
||||
ret = v;
|
||||
|
|
Loading…
Reference in New Issue