我正在使用角树组件,我需要用click+shift键实现多个选择。谁能帮上忙求你了?这就是我现在拥有的。monitoring.ts文件:
import { ITreeOptions, TreeNode} from 'angular-tree-component';
@ViewChild('tree') tree: any;
treeOptions: ITreeOptions = {
getChildren: this.getChildren.bind(this),
useVirtualScroll: true,
nodeHeight: 22
};monitoring.html文件:
<tree-root #tree [nodes]="nodes" [focused]="true" [options]="treeOptions" (updateData)="treeUpdate()" >
...
</tree-root>发布于 2021-08-20 14:10:53
我已经使用shift+click实现了多选择,如下所示。
private lastSelected = [];
if ($event.shiftKey) {
// Capturing last clicked node details
if (this.lastSelected.length > 1) {
this.lastSelected.pop();
}
const last = { id: node.data.id, level: node.level };
this.lastSelected.push(last);
this.getAllNodeIds(tree.nodes);
// Getting the index of first and last clicked node
const firstClicked = this.nodeIds.indexOf(this.lastSelected[0].id);
const lastClicked = this.nodeIds.indexOf(this.lastSelected[1].id);
this.nodeIds.map((val, index) => {
if (firstClicked > lastClicked) {
if (index >= lastClicked && firstClicked > index) {
const currentNode = tree.getNodeById(val);
TREE_ACTIONS.TOGGLE_ACTIVE_MULTI(tree, currentNode, $event);
}
} else {
if (index > firstClicked && lastClicked >= index) {
const currentNode = tree.getNodeById(val);
TREE_ACTIONS.TOGGLE_ACTIVE_MULTI(tree, currentNode, $event);
}
}
});
}
public getAllNodeIds(tree): void {
if (tree) {
for (const val of tree) {
this.nodeIds.push(val.id);
const childrenCount = val.children ? val.children.length : 0;
if (val.hasChildren || childrenCount > 0) {
this.getAllNodeIds(val.children);
}
}
}
return;
}https://stackoverflow.com/questions/64532976
复制相似问题