const treeFilter = (node, action) => {
if (!node) {
return;
}
action(node)
var stack = [];
stack.push(node);
var tmpNode;
while (stack.length > 0) {
tmpNode = stack.pop();
if (!tmpNode) return
if (tmpNode.children && tmpNode.children.length > 0) {
var i = tmpNode.children.length - 1;
for (i = tmpNode.children.length - 1; i >= 0; i--) {
action(tmpNode.children[i], tmpNode.children, i)
stack.push(tmpNode.children[i]);
}
} else {
action(tmpNode)
}
}
}