0

在尝试对一些拖放功能进行原型设计时,我遇到了 ng2-dragula 项目。我想知道如何将以下结构分组为一个“德雷克”实体?

<div>
   <img .../>
   <img .../>
   <span>...</span>
</div>

当我在 div 中添加 [dragula] 时,div 中的每个项目都被认为是一个单独的可拖动项目。我想将它们组合为一个可拖动的项目。

谢谢!

4

1 回答 1

0

在您的情况下,您需要使用dragulaModel

例子

<div class='wrapper'>
  <div class='container' [dragula]='"another-bag"' [dragulaModel]='many'>
    <div *ngFor='let text of many' [innerHtml]='text'></div>
  </div>
  <div class='container' [dragula]='"another-bag"' [dragulaModel]='many2'>
    <div *ngFor='let text of many2' [innerHtml]='text'></div>
  </div>
</div>

class RepeatExample {
  public many: Array<User> = [{'id':123,'name':'stack'},{'id':1234,'name':'stackover'}];
  public many2: Array<User> = [];

  constructor(private dragulaService: DragulaService) {
    dragulaService.dropModel.subscribe((value) => {
      this.onDropModel(value.slice(1));
    });
    dragulaService.removeModel.subscribe((value) => {
      this.onRemoveModel(value.slice(1));
    });
  }

  private onDropModel(args) {
    let [el, target, source] = args;
    // do something else
  }

  private onRemoveModel(args) {
    let [el, source] = args;
    // do something else
  }
}
于 2017-04-28T14:28:00.587 回答