1

I'm developing an app using Ionic 3 and Angular 4 frameworks and Ng-Dragula library.

I need more detailed control over drag and drop of elements provided by Ng-Dragula.

For example, I have three columns.

I want the user can move itens:

  • From first column to second column;
  • From second column to third column;
  • From third column to second column.

I don't want user can move itens:

  • From first column to third column.
  • From second column to first column.
  • From third column to first column.

How can I set this detailed constraints?

4

1 回答 1

1

您可以在每个容器(每列)上设置选项,其中包含一个“接受”函数,该函数确定是否可以将特定项目放在特定容器上的特定位置。

例如,

dragulaService.setOptions('column-1', {
      accepts: function(el, target, source, sibling) {
          // return true to allow drop, false to disallow
      }
    })

根据https://github.com/bevacqua/dragula#optionsaccepts的文档,这个函数的参数是:

  • el - 被丢弃的物品

  • target - 项目被丢弃的容器

  • source - 从中​​拖动项目的容器

  • 兄弟 - 目标容器中的项目被删除之前的项目,如果作为最后一个项目被删除,则为 null

您将返回true以允许下降,false以防止下降。

于 2018-01-07T17:15:02.820 回答