如何使用cdkDropListEnterPredicate来检查多个条件? [英] How to use cdkDropListEnterPredicate to check against multiple conditions?

查看:128
本文介绍了如何使用cdkDropListEnterPredicate来检查多个条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个可拖动列表连接到多个放置区域,但是需要根据应用程序内已设置的变量来限制可以拖动的项目.例如,如果我有以下内容:

I have multiple draggable lists connected to multiple drop zones, but need to limit which items can be dragged based on variables already set within the app. For example, if I have the following:

this.maxVirtuePts = 10;
this.reqSocialStatus = false;
this.allowedTheGift = true;
this.maxHermeticMajorVirtue = 1;

对于maxVirtuePts,如何将放置区域中的项目数量限制为10?对于reqSocialStatus,如何检查放置区域中至少有一项?对于allowedTheGift,我如何检查放置项目的名称是否包含特定文本?对于maxHermeticMajorVirtue,如何检查是否存在从特定列表中删除的项目,以避免从同一来源列表中添加其他项目?

For maxVirtuePts, how do I limit the amount of items in the drop zone to 10? For reqSocialStatus, how do I check that at least one item exists in a dropped zone? For allowedTheGift, how do I check if the name of the dropped item contains specific text? For maxHermeticMajorVirtue, how do I check if a dropped item from a specific list already exists to avoid adding additional items from the same origin list?

如果任何人都可以建议或提供有关如何有效使用cdkDropListEnterPredicate的示例,将不胜感激.

If anyone can suggest or provide examples of how to effectively use cdkDropListEnterPredicate, it would be much appreciated.

添加了StackBlitz: https://stackblitz.com/edit/angular-flpx5t

Added a StackBlitz: https://stackblitz.com/edit/angular-flpx5t

推荐答案

我最终使用了cdkDropListEnterPredicate,但是只有最后的检查会阻止其他项目的转移.为了进行最终检查,我将其他条件计算为变量.

I ended up using cdkDropListEnterPredicate, but only the final check that would block further items being transferred. To get to the final check, I calculated the other conditions as variables.

这篇关于如何使用cdkDropListEnterPredicate来检查多个条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆