使用Dynatree将节点从一棵树移动到另一棵树

时间:2012-09-28 09:00:37

标签: python django dynatree

我目前正在开发一个django项目,我正在使用dynatree来构建treeview。 我有两棵树,第一棵树有用户可以选择的项目,所选项目将被移动到第二棵树。有没有办法可以在dynatree中这样做?并且有一个选项供用户“取消选择”该项目,以便所选项目将移回第一棵树。因此,当用户取消选择该项目时,如何将项目移回其原始父节点?提前谢谢..

3 个答案:

答案 0 :(得分:2)

我使用上下文菜单的复制/粘贴概念解决了我的问题。 对于第二个问题,我使用全局变量来存储原始父节点,因此当用户取消选择该项时,它将移回其原始父节点。

答案 1 :(得分:1)

我在DIV dvAllLetterTemplates(包含主列表)和要复制项目的DIV dvUserLetterTemplates上有一个dynamTree。


//Select the Parent Node of the Destination Tree
var catNode = $("#dvUserLetterTemplates").dynatree("getTree").selectKey(catKey, false);
if (catNode != null) {
//Select the source node from the Source Tree
    var tmplNode = $("#dvAllLetterTemplates").dynatree("getTree").selectKey(arrKeys[i], false);
    if (tmplNode != null) {
        //Make a copy of the source node
        var ndCopy = tmplNode.toDict(false, null);
        //Add it to the parent node
        catNode.addChild(ndCopy);
        //Remove the source node from the source tree (to prevent duplicate copies
        tmplNode.remove();
        //Refresh both trees
        $("#dvUserLetterTemplates").dynatree("getTree").redraw();
        $("#dvAllLetterTemplates").dynatree("getTree").redraw();
     }
}

答案 2 :(得分:0)

'selected'和'active'之间存在差异。 选择通常使用复选框完成,而只能激活一个节点(通常通过鼠标单击)。 第二次单击活动节点不会触发'onActivate'事件,但是您可以实现'onClick'处理程序来捕获它并调用node.deactivate()

相关问题