cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
36 lines (35 loc) • 794 B
JavaScript
function eachAfter(root, callback, separation) {
var nodes = [root];
var next = [];
var node;
while (node = nodes.pop()) {
next.push(node);
if (node.isExpand) {
var children = node.children;
if (children.length) {
for (var i = 0; i < children.length; i++) {
nodes.push(children[i]);
}
}
}
}
while (node = next.pop()) {
callback(node, separation);
}
}
function eachBefore(root, callback) {
var nodes = [root];
var node;
while (node = nodes.pop()) {
callback(node);
if (node.isExpand) {
var children = node.children;
if (children.length) {
for (var i = children.length - 1; i >= 0; i--) {
nodes.push(children[i]);
}
}
}
}
}
export { eachAfter, eachBefore };