diff --git a/src/react/ReactChildren.js b/src/react/ReactChildren.js index bbc07d81edaad3705a3dca0942e1cbc01bff2624..38a890e4b354a0a15ba65441d059741a512439ba 100644 --- a/src/react/ReactChildren.js +++ b/src/react/ReactChildren.js @@ -1,8 +1,19 @@ function mapChildren(children, func, context) { - //TODO实现此mapChildren方法 - return children; + if (!children) return children; + let result = []; + mapChildren(children, func, context, result); + return result; } -export { - mapChildren as map, -}; \ No newline at end of file +function mapChildren(children, func, context, result) { + children.forEach((child, index) => { + if (Array.isArray(child)) { + return childrenMap(child, func); + } + func.call(context, child, index).forEach((item, ind) => { + item.key = "." + (child.key || index) + "/." + (item.key || ind); + result.push(key); + }); + }); +} +export { mapChildren as map };