Skip to content

Commit

Permalink
perf: Linkage of a single subtree to its parent
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoJiSen committed Jun 3, 2024
1 parent df76fc7 commit e870bda
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/app/elements/asset-tree/asset-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,28 @@ export class ElementAssetTreeComponent implements OnInit {
}
}

checkHasParent(node) {
const prNode = node.getParentNode();
if (prNode !== null) {
prNode.checked = !prNode.checked;
this.checkHasParent(prNode);
}
}

onBatchSelect() {
const parentNode = this.rightClickSelectNode;
const tree = this.rightClickSelectNode.ztree;
const currentChecked = tree.setting.check.enable;

this.rightClickSelectNode.checked = !this.rightClickSelectNode.checked;
// 但 select 是展开子项的 item 时的联动
if (parentNode.children && parentNode.children.length > 0) {
const childrenNode = parentNode.children;
return childrenNode.forEach(item => item.checked = !item.checked);
}

// 当所选 item 为深层次的子节点时
this.checkHasParent(parentNode);
parentNode.checked = !parentNode.checked;

if (currentChecked) {
tree.checkAllNodes(false);
Expand Down

0 comments on commit e870bda

Please sign in to comment.