Created
November 10, 2017 22:48
-
-
Save sabha/b2bb02bffdf90f0cf3c57c9c442e43fe to your computer and use it in GitHub Desktop.
Recursion React Children
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var childrens = [{name: 'ql-0', childrens : [ { name: 'ql-0-0' }] },{name: 'ql-1'}, {name: 'ql-2', childrens : [ { name: 'ql-2-0' }, { name: 'ql-2-1' }] }] | |
function recursive(children, i){ | |
return children.map((child, index) => { | |
if(child.childrens) return Object.assign({},child,{index: `${i}-${index}`, childrens: recursive(child.childrens, `${i}-${index}`)}); | |
else return Object.assign({},child,{index: `${i}-${index}`}); | |
}) | |
} | |
var a = recursive(childrens,'ql'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment