ExtJS5 tree dragdrop deep copy

2019-08-02 21:15发布

问题:

In ExtJS5 I have a TreePanel with drag drop enabled. When I drag a node with children from a source tree to a target tree only the parent node is copied.

If I try a deep clone in the 'beforedrop' listener, it fails with the following error: Ext.data.Model.constructor(): Bad Model constructor argument 2 - "session" is not a Session

The view has a viewcontroller but does not have a viewmodel.

Tree definition in view:

xtype: 'treepanel',
                    itemId: 'myProjectsTree',
                    rootVisible: false,
                    viewConfig: {
                        plugins: {
                            ptype: 'treeviewdragdrop',
                            enableDrag: false,
                            enableDrop: true
                        },
                        listeners: {                            
                            beforedrop: 'doDrop',....

In controller:

doDrop: function(dropNode, dragNode, overModel) {
        var node = dragNode.records[0]; 
        var clonedNode = node.copy('111', true);<--- failed here

I have seen sessions defined in a viewmodel scenario. Does the copy function need to have viewmodel session defined ? Is there any way around this. Is there a bug in ExtJS5.

Any help is greatly appreciated!

回答1:

AFAIK there is bug in EXT JS related to copying tree nodes (EXTJS-13725). You should modify/override copy method in Ext.data.NodeInterface:

// copy: function(newId, deep) {
copy: function(newId, session, deep) {
    var me = this,
        result = me.callParent(arguments),
        len = me.childNodes ? me.childNodes.length : 0,
        i;


    if (deep) {
        for (i = 0; i < len; i++) {
            // result.appendChild(me.childNodes[i].copy(undefined, true));
            result.appendChild(me.childNodes[i].copy(undefined, session, true));
        }
    }
    return result;
}

Basically in original code there is no session argument, while there should be.



回答2:

Or set copy:true

viewConfig: {
        plugins: {
            ptype: 'gridviewdragdrop',
            enableDrag: true,
            enableDrop: false,
            ddGroup: 'selDD',
            copy: true
        },


标签: tree extjs5