我正在使用 druska/native_js_drag_and_drop_helper.js 来自动化angular-drag-and-drop-lists
问题:
即使之后event.dataTransfer.setData(mimeType,angular.toJson(item))
dataTransfer.types
未设置或可能不允许在 dragstart 和 drop 事件中读取
观察:在手动拖放dragstart事件期间
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
观察:使用自定义事件时
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)
我在用
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:{}
}
我无法初始化 dataTransfer 对象。dataTransfer.items 和 dataTransfer.types 是只读属性,我不知道如何正确初始化它们。MDN 数据传输