ExtJS5树拖放拖放深层复制 [英] ExtJS5 tree dragdrop deep copy
问题描述
在ExtJS5中,我有一个启用了拖放功能的TreePanel. 当我将带有子节点的节点从源树拖到目标树时,只会复制父节点.
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.
如果我尝试在'beforedrop'侦听器中进行深度克隆,它将失败并显示以下错误: Ext.data.Model.constructor():错误的模型构造函数参数2-会话"不是会话
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
该视图具有ViewController,但没有ViewModel.
The view has a viewcontroller but does not have a viewmodel.
视图中的树定义:
xtype: 'treepanel',
itemId: 'myProjectsTree',
rootVisible: false,
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop',
enableDrag: false,
enableDrop: true
},
listeners: {
beforedrop: 'doDrop',....
在控制器中:
doDrop: function(dropNode, dragNode, overModel) {
var node = dragNode.records[0];
var clonedNode = node.copy('111', true);<--- failed here
我已经看到了在视图模型场景中定义的会话. 复制功能是否需要定义viewmodel会话? 有没有办法解决. ExtJS5中有错误吗?
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.
任何帮助将不胜感激!
推荐答案
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.
这篇关于ExtJS5树拖放拖放深层复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!