From d0d902a6bec6c3cecc6580cd87116dd24bb5bc4d Mon Sep 17 00:00:00 2001 From: catchonme Date: Thu, 22 Aug 2019 10:33:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=87=BD=E6=95=B0=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/form.ts | 4 ++-- src/utils/helper.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/store/form.ts b/src/store/form.ts index 50578444c..5f5d014be 100644 --- a/src/store/form.ts +++ b/src/store/form.ts @@ -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); } diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 4506082de..4319ec94e 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -726,14 +726,14 @@ export function chainFunctions(...fns:Array<(...args:Array) => 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; }