优化函数名

This commit is contained in:
catchonme 2019-08-22 10:33:27 +08:00
parent 13831522b1
commit d0d902a6be
2 changed files with 5 additions and 5 deletions

View File

@ -29,7 +29,7 @@ import {
guid,
isObject,
isEmpty,
iterateChildren
mapObject
} from '../utils/helper';
import { IComboStore } from "./combo";
import isEqual = require('lodash/isEqual');
@ -182,7 +182,7 @@ export const FormStore = ServiceStore
}
function trimValues() {
let data = iterateChildren(self.data, (item:any) => typeof item === 'string' ? item.trim() : item);
let data = mapObject(self.data, (item:any) => typeof item === 'string' ? item.trim() : item);
self.updateData(data);
}

View File

@ -726,14 +726,14 @@ export function chainFunctions(...fns:Array<(...args:Array<any>) => void>):(...a
}
}
export function iterateChildren(value: any, fn: Function): any {
export function mapObject(value: any, fn: Function): any {
if (Array.isArray(value)) {
return value.map(item => iterateChildren(item, fn));
return value.map(item => mapObject(item, fn));
}
if (isObject(value)) {
let tmpValue = {...value};
Object.keys(tmpValue).forEach(key => {
(tmpValue as PlainObject)[key] = iterateChildren((tmpValue as PlainObject)[key], fn);
(tmpValue as PlainObject)[key] = mapObject((tmpValue as PlainObject)[key], fn);
});
return tmpValue;
}