在尝试创建一些拖放功能时,我遇到了ng2-dragula项目。我想知道如何将以下结构分组为一个'drake'实体?
<div>
<img .../>
<img .../>
<span>...</span>
</div>
当我在div中添加[dragula]时,div中的每个项目都被视为一个单独的可拖动项目。我想将它们合并为一个可拖动的项目。
谢谢!
答案 0 :(得分: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
}
}