0

我正在使用 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 数据传输

4

1 回答 1

0

问题是 setData dint 具有设置 DataTransfer.types 的代码,该类型在拖放期间由 angular-drag-and-drop-lists 使用。

        setData: function(type,val) {
            this.data[type] = val
            this.types[0] = type
        }

以上更改修复了问题。现在使用本机 js 拖放工作正常

于 2017-04-18T07:01:10.553 回答