|
@@ -384,34 +384,36 @@ class filterGatherTree extends baseTree {
|
|
|
return item;
|
|
|
}
|
|
|
|
|
|
- sortTreeNodeCustom(field, fun, isResort) {
|
|
|
+ generateSortNodes() {
|
|
|
const self = this;
|
|
|
+ const addSortNode = function (node) {
|
|
|
+ self.nodes.push(node);
|
|
|
+ for (const c of node.children) {
|
|
|
+ addSortNode(c);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ this.nodes = [];
|
|
|
+ for (const n of this.children) {
|
|
|
+ addSortNode(n);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sortTreeNodeCustom(fun) {
|
|
|
const sortNodes = function (nodes) {
|
|
|
- nodes.sort(function (a, b) {
|
|
|
- return fun(a[field], b[field]);
|
|
|
- });
|
|
|
+ nodes.sort(fun);
|
|
|
for (const [i, node] of nodes.entries()) {
|
|
|
node.order = i + 1;
|
|
|
}
|
|
|
- };
|
|
|
- const addSortNodes = function (nodes) {
|
|
|
- if (!nodes) { return }
|
|
|
- for (let i = 0; i < nodes.length; i++) {
|
|
|
- self.nodes.push(nodes[i]);
|
|
|
- nodes[i].index = self.nodes.length - 1;
|
|
|
- if (!isResort) {
|
|
|
- nodes[i].children = self.getChildren(nodes[i]);
|
|
|
+ for (const node of nodes) {
|
|
|
+ if (node.children && node.children.length > 1) {
|
|
|
+ sortNodes(node.children);
|
|
|
}
|
|
|
- sortNodes(nodes[i].children);
|
|
|
- addSortNodes(nodes[i].children);
|
|
|
}
|
|
|
};
|
|
|
this.nodes = [];
|
|
|
- if (!isResort) {
|
|
|
- this.children = this.getChildren();
|
|
|
- }
|
|
|
+ this.children = this.getChildren(null);
|
|
|
sortNodes(this.children);
|
|
|
- addSortNodes(this.children);
|
|
|
+ this.generateSortNodes();
|
|
|
}
|
|
|
}
|
|
|
|