Angular 拖放 : can Enter predicate verify at which index the item is dropped?

标签 angular predicate angular-cdk-drag-drop

我正在使用 Angular DragDropModule,我想将一个对象从一个列表拖动到另一个列表。 这工作完美,但我需要只在到达列表的第一个或最后一个索引处删除我的对象。 例子here显示带有输入谓词的数字列表,该谓词仅允许 Sprite 数字,但我想知道如何解决我的问题。

我希望我说得足够清楚。如果您知道使用谓词以外的其他方法来解决我的问题也没关系。

谢谢!

最佳答案

我想我只是找到了解决问题的方法。事件 cdkDropListDropped 提供了一个“currentIndex”属性,表示刚刚删除项目的索引,因此在“drop”函数中,我刚刚在传输项目之前添加了下面的验证:

drop(event: CdkDragDrop<Object[]>) {
   if (event.currentIndex === 0 || event.currentIndex === arrivalList.length) {
       ...
       ...
       ...
    }
}

我希望我能很好地解释它并且它会对某人有所帮助。

关于 Angular 拖放 : can Enter predicate verify at which index the item is dropped?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63192567/

相关文章:

asp.net - 使用 Find 方法在通用列表中查找对象

C# List.Find 方法 - 如何将值传递给谓词?

c++ - 如何存储 CUDA 内核函数的 bool 结果

angular - 错误类型错误 : Cannot read property 'length' of undefined in Angular 7 Drag and Drop

contenteditable 不适用于 cdkDrag

html - Angular Material 2 : How to put a fab button on top of the md-table at the bottom right corner?

angular - 在不调用根组件的情况下调用 Angular 组件

angularjs - Angular 2 获取 JSON 数组中单个条目的值

angular - 如何在 angular rc.5 中引入的新 bootstrapModule 中使用旧版提供程序和指令