drag-and-drop - 通缉: Directions/ideas for a custom tree-to-tree drag'n'drop implementation in ExtJS

标签 drag-and-drop extjs tree

我需要一些关于 ExtJS 中两棵树之间拖放的组合功能。

第一个所需功能非常简单,只是将内置拖放功能隔离到单个

Standard tree drag'n'drop

第二个必需的功能是我不希望用户能够从左树中拖动节点并将其放在左树中的任何节点上>右树

One way non destructive drag'n'drop

该操作不应从左树中删除节点,从而可能将同一节点从左树拖动到中的多个位置右树

我的问题是:我应该采取哪种方法来组合这两个功能,利用 TreePanel 对象中现有的可能性,而无需再次发明轮子?我不是在寻找完整的解决方案(虽然这会很好;-)),而是在寻找如何处理拖放区域、事件等。

最佳答案

好的。我已经考虑这个问题有一段时间了,以下方法似乎对我有用:)

我已将树配置如下:

listeners:
{
    beforenodedrop: function (dropEvent) {
        // Does this node come from the right tree?
        if (dropEvent.source.tree.id !== dropEvent.tree.id) {
            // The node should be discarded.
            dropEvent.dropNode.parentNode.removeChild(dropEvent.dropNode, true);

            // The node has been discarded, return drop succeeded.
            dropEvent.dropStatus = true;
            return false;
        }
        return true;
    },  
    nodedragover: function (dragevent) {
        // If the node comes from the right tree, it is allowed to be dropped here.
        if (dragevent.source.tree.id !== dragevent.tree.id) {
            return true;
        }
        // A node from this tree is not allowed to be dropped.
        return false;
    }
}

树的配置如下:

listeners:
{   
    beforenodedrop: function (dropEvent) {
        // Does this node come from the left tree?
        if (dropEvent.source.tree.id !== dropEvent.tree.id) {
            // The node should be cloned and inserted in the right tree.

            // Copy the node.
            var node = dropEvent.dropNode; // the node that was dropped
            var nodeCopy = new Ext.tree.TreeNode( // copy it
                Ext.apply({}, node.attributes)
            );
            // Match the id's.
            nodeCopy.id = Ext.id(null,'newnode') + '_' + node.id;

            // Find the right place to put it.
            if (dropEvent.target.parentNode === dropEvent.tree.getRootNode()) {
                // The node is placed on a folder, thus drop it there.
                dropEvent.target.appendChild(nodeCopy);
            } else {
                // The node is placed inside a folder, thus place it in there.
                dropEvent.target.parentNode.appendChild(nodeCopy);
            }

            // The node has been dropped, return okay and stop further process.
            dropEvent.dropStatus = true;
            return false;
        }           
        // Just use the normal builtin drag and drop.
        return true;
    }
}

两棵树都已设置为启用拖放:

enableDD: true

所有叶节点都有以下配置:

allowDrop: true,
draggable: true

所有文件夹均设置为:

allowDrop: true,
draggable: false

结论是,我选择覆盖树面板中的一些内置拖放方法,同时仍然保留内置功能。<​​/p>

关于drag-and-drop - 通缉: Directions/ideas for a custom tree-to-tree drag'n'drop implementation in ExtJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3510016/

相关文章:

javascript - Angular Material CDK Drop 事件未触发

javascript - listView 中的 extjs 图像,带有工具提示和条件颜色

linux - BASH - 只打印路径中最深的目录

c# - ANTLR 在树遍历中删除节点

android - 将 RecyclerView 项目拖放后在 SQLite 中的新位置存储

WPF对角线拖放

Android getWidth、getHeight、getLeft、getRight 在 setScaleX()、setScaleY() 之后不正确

javascript - 在 ExtJS 中居中对齐按钮

extjs - EXT JS 关闭弹窗

algorithm - 成绩较好但jee排名较低的学生人数