问题
I am using druska/native_js_drag_and_drop_helper.js to automate angular-drag-and-drop-lists
Issue :
Even after event.dataTransfer.setData(mimeType,angular.toJson(item))
dataTransfer.types
is not set or probably not allowed to read in dragstart and drop event
Observation : during manual drag drop dragstart event
dataTransfer {dropEffect: "none", effectAllowed: "move", items: DataTransferItemList, types: Array(1), files: FileList}
dropEffect:"move"
effectAllowed:"move"
files:FileList
items:DataTransferItemList
types:Array(0)
__proto__:DataTransfer
DataTransferItemList {0: DataTransferItem, length: 1}
length: 0
__proto__: DataTransferItemList
DataTransferItem {kind: "string", type: "application/x-dnd"}
kind: ""type: ""
__proto__: DataTransferItem
Observation:when using custom event
dataTransfer:Object
data:Object
application/x-dnd:"[{"id":"706","title":"Ab 2","drag":false,"selected":true}]"
__proto__:Object
dropEffect:"move"
effectAllowed:"move"
getData:function (type)
setData:function (type,val)
files:Object
items:Object
types:Array(0)
I am using
var event = new CustomEvent("CustomEvent", {"cancelable": true})
event.initCustomEvent(type, true, true, null);
event.dataTransfer = {
data: {
},
setData: function(type,val) {
this.data[type] = val
},
getData: function(type) {
return this.data[type]
},
dropEffect: 'move',
effectAllowed:'move',
types: [],
items:{},
files:{}
}
I am not able to initialize dataTransfer object. dataTransfer.items and dataTransfer.types being read only property , i don't know how to correctly initialize them .MDN dataTransfer
回答1:
Issue was setData dint had code to set DataTransfer.types that was being used by angular-drag-and-drop-lists during drag drop.
setData: function(type,val) {
this.data[type] = val
this.types[0] = type
}
Above changes fixed the issue .Drag drop working fine now using native js
来源:https://stackoverflow.com/questions/43391567/html5-dragdrop-datatransfer-types-not-set-after-event-datatransfer-setdatamimet