|
|
@ -170,15 +170,15 @@ export class Tree { |
|
|
|
|
|
|
|
|
|
|
|
initTree(nodes) { |
|
|
|
initTree(nodes) { |
|
|
|
this.clear(); |
|
|
|
this.clear(); |
|
|
|
const queue = []; |
|
|
|
const queue = new Set(); |
|
|
|
each(nodes, (i, node) => { |
|
|
|
each(nodes, (i, node) => { |
|
|
|
const n = new Node(node); |
|
|
|
const n = new Node(node); |
|
|
|
n.set("data", node); |
|
|
|
n.set("data", node); |
|
|
|
this.addNode(n); |
|
|
|
this.addNode(n); |
|
|
|
queue.push(n); |
|
|
|
queue.add(n); |
|
|
|
}); |
|
|
|
}); |
|
|
|
while (!isEmpty(queue)) { |
|
|
|
queue.forEach(parent => { |
|
|
|
const parent = queue.shift(); |
|
|
|
queue.delete(parent); |
|
|
|
const node = parent.get("data"); |
|
|
|
const node = parent.get("data"); |
|
|
|
each(node.children, (i, child) => { |
|
|
|
each(node.children, (i, child) => { |
|
|
|
const n = new Node(child); |
|
|
|
const n = new Node(child); |
|
|
@ -186,7 +186,7 @@ export class Tree { |
|
|
|
queue.push(n); |
|
|
|
queue.push(n); |
|
|
|
this.addNode(parent, n); |
|
|
|
this.addNode(parent, n); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_toJSON(node) { |
|
|
|
_toJSON(node) { |
|
|
@ -265,7 +265,7 @@ export class Tree { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (temp != null) { |
|
|
|
if (temp != null) { |
|
|
|
queue = queue.concat(temp.getChildren()); |
|
|
|
queue.push(...temp.getChildren()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|