From c60577d70b44ba5ee48b452c93dc6beb6dc95d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=98=8E=E8=88=AA?= <7421955+li_ming_hang@user.noreply.gitee.com> Date: Tue, 7 Apr 2020 21:50:50 +0800 Subject: [PATCH] update src/react/ReactChildren.js. --- src/react/ReactChildren.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/react/ReactChildren.js b/src/react/ReactChildren.js index bbc07d8..4e7b1fe 100644 --- a/src/react/ReactChildren.js +++ b/src/react/ReactChildren.js @@ -3,6 +3,22 @@ function mapChildren(children, func, context) { return children; } +function map(children, func, context) { + let arr = [] + if (!Array.isArray(children)) { + return func(children,0) + } + children.map((item, index) => { + if (Array.isArray(item)) { + arr.push(...item.map(subItem => func(subItem, index))) + } else { + arr.push(func(item,index)) + } + }) + return arr + +} + export { mapChildren as map, }; \ No newline at end of file -- Gitee