AngularCDKDragDrop-如何防止将拖动的项目从一个列表拖动到另一个列表?
创始人
2024-10-23 13:31:37
0

要防止将拖动的项目从一个列表拖动到另一个列表,可以使用Angular CDKDragDrop中的dropContainer属性。

  1. 在源列表和目标列表的HTML元素中,为dropContainer属性设置不同的ID。

示例源列表:

{{item}}

示例目标列表:

{{item}}
  1. 在drop事件处理程序中检查dropContainer属性是否匹配。
onDrop(event: CdkDragDrop) {
  // Get the container ID of the drop list the item was dropped into
  const currentContainerId = event.container.element.nativeElement.id;

  // If the item was dropped into the same list it came from
  if (event.previousContainer === event.container) {
    // Do something
  } 
  // If the item was dropped into a different list
  else if (currentContainerId !== event.previousContainer.element.nativeElement.id) {
    // Prevent the item from being dropped into the different list
    return;
  }

  // Do something else
}

在这个例子中,我们将从每个列表中获取相应的dropContainer ID,并检查是否匹配。如果当前的dropContainer ID与之前的dropContainer

相关内容

热门资讯

透视有挂!wepokerplu... 透视有挂!wepokerplus透视脚本免费,微乐小程序黑科技辅助工具2026最新推荐,揭幕透视(有...
透视有挂!wepoker怎么破... 透视有挂!wepoker怎么破解游戏,wejoker辅助软件视频(透视)一贯有工具(哔哩哔哩)是不是...
近日!hh poker插件下载... 近日!hh poker插件下载,微乐广西麻辣辅助器,推荐脚本(有挂透明挂)-哔哩哔哩hh poker...
脚本推荐!wepoker怎么设... 脚本推荐!wepoker怎么设置盖牌,wepokerplus外g挂(透视)确实有app(哔哩哔哩)1...
出现新变化!竞技联盟透视插件,... 出现新变化!竞技联盟透视插件,微乐贵阳足鸡麻将开挂,详情脚本(真的有挂)-哔哩哔哩1、下载好竞技联盟...
脚本解密!wpk德州局透视,w... 脚本解密!wpk德州局透视,wpk模拟器多开(透视)果然是有器(哔哩哔哩)1、每一步都需要思考,不同...
透视演示!htx矩阵wepok... 透视演示!htx矩阵wepoker辅助,WePoKer钻石一贯真的有教程,八分钟教程(有挂猫腻)1、...
最终!线上德州的辅助器是什么,... 最终!线上德州的辅助器是什么,微乐广西自建房免费黑科技下载,透视透视(有挂猫腻)-哔哩哔哩1、进入游...
透视操作!hhpoker可以控... 透视操作!hhpoker可以控制吗,HHpoker德州竟然真的是有安装,2分钟教程(详细教程)1、操...
围绕透视问题!德州hhpoke... 围绕透视问题!德州hhpoker是真的吗,小程序微乐贵阳捉鸡麻将挂,详情透视(有挂猫腻)-哔哩哔哩所...