weixin_42399237 2010-09-17 10:05
浏览 289
已采纳

extjs 2个tree节点拖拽问题

ext官方例子 2个tree节点拖拽都是 第一个tree的node拖拽到第2个tree上, 第1个tree上刚才拖拽的node没有了
我想要的效果是[color=red]第1个tree的node拖完 node依然存在[/color],而且[color=red]右侧一个目录下 只有一个唯一的节点[/color] (就是拖拽一次到某个目录下,再次拖拽到刚才的目录下 alert一下该目录以及存在此节点)
希望能给出可以测试的代码 不甚感谢各位

  • 写回答

5条回答 默认 最新

  • iteye_9229 2010-09-17 14:34
    关注

    这个在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]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog