angular - 在多个列表之间拖放
问题描述
我有四个不同对象(A、B、C、D)的 4 个列表。
有没有办法将名称与这些列表中的每一个相关联?换句话说,列表 A 是 A,B 是 B ...
我打算拖放一个对象,同时知道它来自哪个列表以及它去了哪里。
我用它来找出自动生成的列表值console.log ("FROM" + event.previousContainer.id)
console.log ("TO" + event.container.id)
,问题是这些值有时会有所不同,它们并不总是相同的,如果你使用条件它可能会停止工作。
有没有办法从它是对象的列表和它被丢弃的列表中分配或总是获得相同的名称?
谢谢
.ts
drop(event: CdkDragDrop<string[]>) {
console.log("FROM" + event.previousContainer.id)
console.log("TO" + event.container.id)
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
);
}
}
解决方案
在您的drop
函数内部调用此事件数据:
对于上一个容器:
event.previousContainer.element.nativeElement.id
对于您当前的容器:
event.container.element.nativeElement.id
然后在您的 HTML 中向列表元素添加一个 ID,如下所示:
<div ... #activeList="cdkDropList" id="list-A" ...>
推荐阅读
- reactjs - 如何使用 webflux 端点从 React 生成 json 流
- c# - 将 SQL db 导出到 Excel 问题
- r - 使用 R 跨多样本相关性的多基因
- drake - 从 state_output 转换为 RollPitchYaw 时变量 u0_0 没有条目
- buildfire - Buildfire:链接到内部页面/插件
- angular - GoCD - Angular Build 无法执行
- javascript - 如何在 2 个多维数组中找到共同值
- r - 如何缓解线性模型函数中的“可变长度不同”错误
- python-3.x - Python teradata 连接异常 - UdaExec 属性
- node.js - Firebase nodejs 服务错误“AssertionError [ERR_ASSERTION]:缺少路径”