Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 拖放代码适用于ExtJS4.0.7,但不适用于更高版本_Javascript_Extjs_Drag And Drop_Extjs4 - Fatal编程技术网

Javascript 拖放代码适用于ExtJS4.0.7,但不适用于更高版本

Javascript 拖放代码适用于ExtJS4.0.7,但不适用于更高版本,javascript,extjs,drag-and-drop,extjs4,Javascript,Extjs,Drag And Drop,Extjs4,我是ExtJS的新手,我想了解更多关于拖放的工作原理。所以我在看关于这个的文章。我在此基础上编写了一个JS提琴,根据示例使用ExtJS4.0.7。如果我在ExtJS4.1.0或更高版本(例如JSFiddle-with 4.2.0)中交换代码,代码将无法正常工作。只有第一次拖动有效。之后,控制台中会出现大量错误 代码如下: Ext.onReady(function() { Ext.create('Ext.container.Viewport', { layout: 'vbo

我是ExtJS的新手,我想了解更多关于拖放的工作原理。所以我在看关于这个的文章。我在此基础上编写了一个JS提琴,根据示例使用ExtJS4.0.7。如果我在ExtJS4.1.0或更高版本(例如JSFiddle-with 4.2.0)中交换代码,代码将无法正常工作。只有第一次拖动有效。之后,控制台中会出现大量错误

代码如下:

Ext.onReady(function() {
    Ext.create('Ext.container.Viewport', {
        layout: 'vbox',
        items: [{
            xtype: 'panel',
            title: 'Drop a Panel Here',
            listeners: { render: initializeDropTarget },
            cls: 'x-dd-drop-ok',
            layout: {
                type: 'vbox',
                stretch: 'align'
            },
            width: 300,
            height: 300
        }, {
            xtype: 'panel',
            title: 'Drag This Panel',
            draggable: true,
            bodyCls: 'green-body',
            width: 300,
            height: 100
        }, {
            xtype: 'panel',
            title: 'Drag This Panel',
            draggable: true,
            bodyCls: 'blue-body',
            width: 300,
            height: 100
        }, {
            xtype: 'panel',
            title: 'Drag This Panel',
            draggable: true,
            bodyCls: 'red-body',
            width: 300,
            height: 100
        }]
    });
});

/**
 Initialize the DropTarget object associated
 with our panel. The 'cmp' argument will be
 the panel (a Component object).
 */
function initializeDropTarget(targetPanel) {
    // Create the DropTarget object and assign it to the panel. Does not
    // have to be assigned to the panel but needs to be assigned to something,
    // or it will get garbage-collected too soon.
    targetPanel.dropTarget = Ext.create('Ext.dd.DropTarget', targetPanel.el);

    // Called once, when dragged item is dropped in the target area. Return false
    // to indicate an invalid drop. DO NOT MODIFY the UI in
    // this function. Use afterDragDrop and the data object.
    targetPanel.dropTarget.notifyDrop = function(source, evt, data) {
        if(typeof console != "undefined")
            console.log("notifyDrop:" + source.id);

        // The component that was dropped.
        var droppedPanel = Ext.getCmp(source.id);

        // We can't modify the component that was dropped in this
        // function. However, we can add an event handler on the component
        // that will be called shortly.
        //
        // In the handler we clone the component (not strictly necessary, we could
        // do that here) and then remove our old component.
        droppedPanel.dd.afterValidDrop = function() {
            targetPanel.add(droppedPanel.cloneConfig({
                draggable: false,
                title: "Can't Drag This Panel."
            }));

            droppedPanel.destroy();
        };

        return true;
    };

    // Called once, when dragged item enters drop area.
    targetPanel.dropTarget.notifyEnter = function(source, evt, data) {
        if(typeof console != "undefined")
            console.log("notifyEnter:" + source.id);

        return this.callParent(Array.prototype.slice.call(arguments));
    };

    // Called once, when dragged item leaves drop area.
    targetPanel.dropTarget.notifyOut = function(source, evt, data) {
        if(typeof console != "undefined")
            console.log("notifyOut:" + source.id);

        return this.callParent(Array.prototype.slice.call(arguments));
    };

    // Called for each mouse movement as dragged item is over the drop area.
    targetPanel.dropTarget.notifyOver = function(source, evt, data) {
        if(typeof console != "undefined")
            console.log("notifyOver:" + source.id);

        return this.callParent(Array.prototype.slice.call(arguments));
    };
}
我需要更改什么来修复此问题



更新:我可以看到它与ghost元素和行
droppedPanel.destroy()有关

拖放面板显然是在
notifyDrop
之后的某个位置使用的(当抛出异常时,您可以在堆栈跟踪
stopDrag
方法中看到)

最简单的解决方法是延迟
销毁
调用或使用
结束拖动
回调:

droppedPanel.dd.endDrag = function() {
    droppedPanel.destroy();
};
工作样本: