datamapping 支持复杂用法

This commit is contained in:
liaoxuezhi 2019-06-24 20:33:01 +08:00
parent dc10730381
commit 4e83fcd316
2 changed files with 10 additions and 3 deletions

View File

@ -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);

View File

@ -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;