【发布时间】:2017-01-06 19:18:12
【问题描述】:
我有一个带有typescript 的angular2 应用程序。我正在使用ng2-dragula 制作拖放应用程序。
我需要检查一个条件,如果条件为假则恢复拖动,我从here 知道revertOnSpill revertOnSpill:true 可以放回元素到它的第一位。
但是,我不知道在 ng2-dragula 中怎么可能。
我在onDrop 中暗示了它。这是代码
constructor() {
dragulaService.drop.subscribe((value) => {
this.onDrop(value.slice(1));
});
dragulaService.setOptions('second-bag', {
removeOnSpill: true
});
}
private onDrop(args) {
bla
bla
bla
if(err.status=="404")
this.dragulaService.removeModel;
// this.dragulaService.cancel; also tried but did not work
}
这里是html代码:
<div id="toPlay" class="playBox roundedBox" [dragula]="'second-bag'">
<img class="w3-animate-top" [src]="sax_path" alt="sax" id="saxsophone"/>
<img class="w3-animate-top" [src]="drum_path" alt="drum" id="drum"/>
</div>
<div id="scene" [dragula]="'second-bag'">
</div>
Package.json 是:
"dependencies": {
"dragula": "^3.7.2"
},
"peerDependencies": {
"@angular/common": "^2.0.0",
"@angular/core": "^2.0.0",
"@angular/compiler": "^2.0.0",
"@angular/forms": "^2.0.0"
},
"devDependencies": {
"angular-cli": "1.0.0-beta.22-1",
"typescript": "2.0.10"
}
问题是,我不知道如何取消掉落?
【问题讨论】:
-
你使用的是dragula还是ng2-dragula?
-
你也有 ng2-dragula 吗?如果没有,他们有一个专门用于 angular2 的包:github.com/valor-software/ng2-dragula
-
我自己从来没有做过,但我认为
accepts方法(见这里:github.com/bevacqua/dragula)是你所追求的