From 8223e789386d4f01c1a87869cbf8c56b5685894d Mon Sep 17 00:00:00 2001 From: freedomseeker <416317400@qq.com> Date: Tue, 7 Apr 2020 20:29:49 +0800 Subject: [PATCH] #720# --- src/react/ReactChildren.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/react/ReactChildren.js b/src/react/ReactChildren.js index bbc07d8..86c1339 100644 --- a/src/react/ReactChildren.js +++ b/src/react/ReactChildren.js @@ -1,6 +1,20 @@ function mapChildren(children, func, context) { - //TODO实现此mapChildren方法 - return children; + const mapedChildren = flatten(children) + const finalChildren = flatten(mapedChildren.map(func)); + return finalChildren; +} + +function flatten(children) { + const flattenedChildren = []; + children.forEach((item, index) => { + if (item instanceof Array ) { + const temp = flatten(item); + flattenedChildren.push(...temp); + } else { + flattenedChildren.push(item) + } + }) + return flattenedChildren; } export { -- Gitee