Created
March 14, 2013 13:51
-
-
Save heroicyang/5161470 to your computer and use it in GitHub Desktop.
树遍历操作
This file contains hidden or 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 id = 1; | |
(function loop (children) { | |
var nextChildren = []; | |
_.map(children, function (child) { | |
child.uid = child.name + '-' + id; | |
if (child.children && child.children.length > 0) { | |
nextChildren = nextChildren.concat(child.children); | |
} | |
id += 1; | |
}); | |
if (nextChildren.length > 0) { | |
loop(nextChildren); | |
} | |
})(tree.children); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment