Skip to content

Instantly share code, notes, and snippets.

@heroicyang
Created March 14, 2013 13:51
Show Gist options
  • Save heroicyang/5161470 to your computer and use it in GitHub Desktop.
Save heroicyang/5161470 to your computer and use it in GitHub Desktop.
树遍历操作
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