首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Angular cdk/拖放多个cdkDrag元素

Angular cdk/拖放多个cdkDrag元素
EN

Stack Overflow用户
提问于 2020-06-14 17:18:55
回答 1查看 753关注 0票数 0

我在一个角度项目上工作,我想要有列,其中的元素可以放在任何列中,同时,我想拖放列本身来改变列的顺序。

Here is moving the elements between the columns From Trello which I already have

And here is the functionality of changing the order of the columns From Trello that I want to implement如果有一种方法可以实现这个功能,那将会很有帮助。

我目前正在使用cdk/drag-drop在列之间移动元素,但我被困在移动列本身上。我浏览了https://material.angular.io/cdk/drag-drop/examples,但找不到在同一个页面中包含多种类型的ckdDrag元素的方法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-14 23:47:40

没有问题,你可以有一个数组,例如

代码语言:javascript
运行
复制
list = [
    { head: "to do", items: ["Get to work", "Pick up groceries", "Go home", "Fall asleep"] },
    { head: "Done", items: ["Get up", "Brush teeth", "Take a shower", "Check e-mail", "Walk dog"] }
  ];

一个.html

代码语言:javascript
运行
复制
<div cdkDropList (cdkDropListDropped)="dropColumns($event)">
    <div cdkDropListGroup>
        <div class="example-container" *ngFor="let items of list;let i=index" cdkDrag>
            <h2>{{items.head}}</h2>

            <div cdkDropList #todoList="cdkDropList" [cdkDropListData]="items.items"
                class="example-list" (cdkDropListDropped)="drop($event)">
                <div class="example-box" *ngFor="let item of items.items" cdkDrag>{{item}}</div>
            </div>
        </div>
    </div>
</div>

注意,您在<div cdkDropListGroup>中包含了"columns“

并且这两个函数会丢弃

代码语言:javascript
运行
复制
dropColumns(event: CdkDragDrop<string[]>) {
    moveItemInArray(this.list, event.previousIndex, event.currentIndex);
  }
  drop(event: CdkDragDrop<string[]>) {
    if (event.previousContainer === event.container) {
      moveItemInArray(
        event.container.data,
        event.previousIndex,
        event.currentIndex
      );
    } else {
      transferArrayItem(
        event.previousContainer.data,
        event.container.data,
        event.previousIndex,
        event.currentIndex
      );
    }
  }

请参见stackblitz (如果您“从标题拖动”,则需要重新排序“列”)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62370595

复制
相关文章

相似问题

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