【发布时间】:2020-03-16 16:31:37
【问题描述】:
我正在构建和应用程序,其中在一组列中呈现了多个项目。 (为了演示,假设是 4 列)
我正在尝试实现将项目相互拖放的功能,这将导致这两个项目的合并。
typescript 数据结构
Details{
id:number;
columns:Column[];
}
Column{
id:number;
item:Item[];
}
Item{
id:number;
text:string;
}
所以我有详细信息组件:
<div fxLayout="row wrap" fxLayoutAlign="center" fxLayoutGap="5px" cdkDropListGroup>
<column *ngFor="let column of details.columns" [column]="column" fxFlex>
</column>
</div>
和列组件:
<div>
Column Header
</div>
<div cdkDropList
(cdkDropListDropped)="drop($event)"
[cdkDropListData]="column.items"
*ngFor="let item of column.items">
<item cdkDrag [item]="item" [cdkDragData]="item">
</item>
</div>
现在我只是打印它
drop(event: CdkDragDrop<Item[]>) {
console.log(event);
}
每当我现在在 drop 之后打印 event 时,我确实有当前容器的详细信息并移到了,但我需要有关我删除该元素的确切位置(在哪个 item.id 上)的信息,而不是让 item 逃避为默认 cdkDragDrop 行为。之后我会有一些事件来合并后端的东西等。
如果有提示,将不胜感激
【问题讨论】:
-
将链接添加到我目前拥有的示例工作区
标签: angular typescript merge drag-and-drop angular-material-7