Plunker:https://plnkr.co/edit/uZ8mvu6a1LXAsBBY3Shd?p=preview角2 - 拖放回调函数
在顶部我有“小部件”:“文本”和“文本B”,你可以拖放。
下面的小部件你有两个小部件已经在里面的行。 我有一个
- 座集装箱
- 块体行(背景为蓝色)
- 列块(粉红色背景)
- 块(红底)
- 列块(粉红色背景)
- 块体行(背景为蓝色)
基本上就像一个Bootstrap网格。 1)当我把'文本'部件拖到红色块上时,部件被添加,但我没有得到回调'onDragEnter'函数调用。我只能在console.log onDropSucces s。
当我将容器,容器,行,列和块拖动到可以添加逻辑的位置时,我想要调用回调函数。
我试图添加我的功能,但不起作用,无法弄清楚错误在哪里。
我希望有人可以帮助找出这一个。
//Drag functions
drop(item){
alert('dropped')
console.log('dropping event', item)
var target = item.mouseEvent.target,
index;
if(target.classList.contains('row')) {
index = target.getAttribute('data-index');
}
if(target.classList.contains('item') && target.parentNode.classList.contains('row')) {
index = target.parentNode.getAttribute('data-index');
}
if(index) {
console.log(this.containers);
console.log(this.containers[index]);
this.containers[index].widgets.push(item.dragData);
} else {
this.containers.push([ item.dragData]);
}
}
onDropSuccess(widget: any, event: any, objecType: string) {
console.log('dropped on ', objecType)
if(objecType == 'row'){
console.log('dropped on', objecType)
}
else if(objecType == 'block'){
console.log('dropped on ', objecType)
}
this.dragOperation = false;
console.log('onDropSuccess x', widget, event);
console.log('containers', this.containers)
}
onDragStart(widget: any, event: any) {
console.log('onDragStart', widget, event);
}
onDragEnter(widget: any, event: any) {
alert('entered ')
console.log('onDragEnter', widget, event);
console.log('drag enter containers', this.containers)
}
chicken(event) {
console.log('onDragEnter chicken', event);
}
onDragSuccess(widget: any, event: any) {
console.log('onDragSuccess', widget, event);
}
onDragOver(widget: any, event: any) {
console.log('onDragOver', widget, event);
}
onDragEnd(widget: any, event: any) {
console.log('onDragOver', widget, event);
}
onDragLeave(widget: any, event: any) {
console.log('onDragLeave', widget, event);
}
onMouseDown(){
this.dragOperation = true;
console.log('mouse down');
}
onMouseUp(event: any){
console.log(event);
this.dragOperation = false;
}
你有没有考虑过使用RxJS的力量来做到这一点? – danimal
请解释更多,你的想法和方式是什么。因为我是这个 –
的新手这是一个很好的例子:https://egghead.io/lessons/javascript-simple-drag-and-drop-with-observables – danimal