首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何允许多个选择和多个拖放在角树上?

如何允许多个选择和多个拖放在角树上?
EN

Stack Overflow用户
提问于 2020-10-26 07:29:39
回答 1查看 386关注 0票数 1

我正在使用角树组件,我需要用click+shift键实现多个选择。谁能帮上忙求你了?这就是我现在拥有的。monitoring.ts文件:

代码语言:javascript
复制
import { ITreeOptions, TreeNode} from 'angular-tree-component';
  @ViewChild('tree') tree: any;
  treeOptions: ITreeOptions = {
    getChildren: this.getChildren.bind(this),
    useVirtualScroll: true,
    nodeHeight: 22
  };

monitoring.html文件:

代码语言:javascript
复制
<tree-root #tree [nodes]="nodes" [focused]="true" [options]="treeOptions" (updateData)="treeUpdate()"  >
...
 </tree-root>
EN

回答 1

Stack Overflow用户

发布于 2021-08-20 14:10:53

我已经使用shift+click实现了多选择,如下所示。

代码语言:javascript
复制
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;
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64532976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档