ExtJS5 tree dragdrop deep copy

余生颓废 提交于 2019-12-24 11:22:59

问题


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
        },


来源:https://stackoverflow.com/questions/26754929/extjs5-tree-dragdrop-deep-copy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!