ext官方例子 2个tree节点拖拽都是 第一个tree的node拖拽到第2个tree上, 第1个tree上刚才拖拽的node没有了
我想要的效果是[color=red]第1个tree的node拖完 node依然存在[/color],而且[color=red]右侧一个目录下 只有一个唯一的节点[/color] (就是拖拽一次到某个目录下,再次拖拽到刚才的目录下 alert一下该目录以及存在此节点)
希望能给出可以测试的代码 不甚感谢各位
这个在extjs官方论坛上有
[code="js"]
Ext.override(Ext.tree.TreeNode, {
clone: function() {
var atts = this.attributes;
if(this.childrenRendered || this.loaded || !this.attributes.children) {
var clone = new Ext.tree.TreeNode(Ext.apply({}, atts));
}
else {
var newAtts = Ext.apply({}, atts);
newAtts.children = this.cloneUnrenderedChildren();
var clone = new Ext.tree.AsyncTreeNode(newAtts);
}
clone.text = this.text;
for(var i=0; i<this.childNodes.length; i++){
clone.appendChild(this.childNodes[i].clone());
}
return clone;
},
cloneUnrenderedChildren: function() {
unrenderedClone = function(n) {
//n.id = undefined;
if(n.children)
{
for(var j=0; j<n.children.length; j++) {
n.children[j] = unrenderedClone(n.children[j]);
}
}
return n;
};
var c = [];
for(var i=0; i<this.attributes.children.length; i++) {
c[i] = Ext.apply({}, this.attributes.children[i]);
c[i] = unrenderedClone(c[i]);
}
return c;
}
});
[/code]
在拖拽目标树上加监听
[code="js"]
'beforenodedrop': function(e)
{//实现COPY拖拽
if(e.source.tree == e.target.ownerTree)
{
return true;
}
var n = e.dropNode; // the node that was dropped
var existNode = e.target.ownerTree.getNodeById(n.id);
if(e.source.tree.el != e.target.ownerTree.el&&existNode==undefined)
{
e.dropNode = n.clone(); // assign the copy as the new dropNode
}
else
{
return false;
}
}
[/code]
beforenodedrop ( Object dropEvent )
当一个DD对象在置下到某个节点之前触发,用于预处理(preprocessing) 返回false则取消置下 传入的dropEvent处理函数有以下的属性:
tree - TreePanel对象
target - 投下的节点对象(目标)
data - 拖动的数据源
point - 投下的方式-添加、上方或下方
source - 拖动源
rawEvent - 原始鼠标事件
dropNode - 由源提供的置下节点,或在该对象设置你要插入的节点
cancel - 设置为true表示签名投下为不允许
参数项:
dropEvent : Object
事件对象
不无非就是想alert一下,你根据上面代码写个函数不就行了。如果想copy节点的话 节点id是有问题的。
tree.on('beforenodedrop',function(e){
var config = {id:Ext.id()};
Ext.applyIf(config,e.dropNode.attributes); //复制节点属性
e.dropNode.parentNode.appendChild(config); //添加节点
})
上面这段代码是简单 copy 节点;你可以参考改改
请问tree左侧拖拽后,数据还是保持原型不删除,是怎么解决的呢?