问题
Problem : trying to simulate drag drop in frontend that uses angular-drag-and-drop-lists (go to detailed description)
Tried :
1.jquery-simulate: Gives following error
Uncaught TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.
2.drag-drop-helper.js : click happens on item to be dragged
3.drag_to : nothing happens
Need some more suggestions .
Thanks
jquery-simulate: https://github.com/jquery/jquery-simulate
sorry not able to post link for drag_to and drag-drop-helper.js
回答1:
Custom event needed to adjusted like this :
function createCustomEvent(type) {
var event = new CustomEvent("CustomEvent", {"cancelable": true})
event.initCustomEvent(type, true, true, null);
event.dataTransfer = {
data: {
},
setData: function(type,val) {
this.data[type] = val
this.types[0] = type
}
getData: function(type) {
return this.data[type]
},
dropEffect: 'move',
effectAllowed:'move',
types: [],
items: {},
files:{}
}
return event
}
in native js drag drop script and then it works fine
来源:https://stackoverflow.com/questions/43109946/how-to-automate-angular-drag-and-drop-lists