Browse Source

Pull request #3467: FDL-2946 提升大数据量下inittree的速度

Merge in VISUAL/fineui from ~TELLER/fineui:master to master

* commit '72c7d698a453d87f2d6bdc55c4e84f20bb2d6e32':
  🦄 refactor: 修改为forEach
  🐞 fix(FDL-2946): 提升大数据量下inittree的速度
research/test
Teller-杨派 2 years ago
parent
commit
4ce24a019f
  1. 15
      src/core/structure/tree.js

15
src/core/structure/tree.js

@ -30,23 +30,26 @@
initTree: function (nodes) { initTree: function (nodes) {
var self = this; var self = this;
this.clear(); this.clear();
var queue = []; var queue = new Set();
BI.each(nodes, function (i, node) { BI.each(nodes, function (i, node) {
var n = new BI.Node(node); var n = new BI.Node(node);
n.set("data", node); n.set("data", node);
self.addNode(n); self.addNode(n);
queue.push(n); queue.add(n);
}); });
while (!BI.isEmpty(queue)) {
var parent = queue.shift(); queue.forEach(parent => {
queue.delete(parent);
var node = parent.get("data"); var node = parent.get("data");
BI.each(node.children, function (i, child) { BI.each(node.children, function (i, child) {
var n = new BI.Node(child); var n = new BI.Node(child);
n.set("data", child); n.set("data", child);
queue.push(n); queue.add(n);
self.addNode(parent, n); self.addNode(parent, n);
}); });
} });
}, },
_toJSON: function (node) { _toJSON: function (node) {

Loading…
Cancel
Save