需要:ExtJS 中自定义树到树拖放实现的方向/想法

发布于 2024-09-15 00:27:22 字数 526 浏览 3 评论 0原文

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

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

标准树拖放

第二个必需的功能是我不希望用户能够将节点从左树拖放到右树中的任何节点。

单向非破坏性拖放

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

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

I need some combined functionality regarding drag'n'drop between two trees in ExtJS.

The first required feature is very simple and is just the builtin drag'n'drop features isolated to a single tree only.

Standard tree drag'n'drop

The second required feature is that I wan't the user to be able to drag a node from the left tree and drop it at any node in the right tree.

One way non destructive drag'n'drop

The action should not remove the node from the left tree, thus creating the possibility of dragging the same node from the left tree to multiple places in the right tree.

My question is: Which approach should I take to combine these two functionalities, utilizing the existing possibilities in the TreePanel object without inventing the wheel again? I am not looking for a complete solution (it would be nice though ;-) ), but rather how to handle drag/drop-zones, events and so on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦在深巷 2024-09-22 00:27:22

好的。我现在一直在考虑这个问题,以下方法似乎对我有用:)

我已将 left 树配置为:

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;
    }
}

right 树的配置如下这:

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

结论是,我选择覆盖一些内置的拖放方法树面板,同时仍然保持内置功能。

Okay. I have been thinking about this some time now, and the following approach seems to work for me :)

I have configured the left tree as this:

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;
    }
}

The right tree is configured like this:

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;
    }
}

Both trees has been set to enable Drag'n'Drop:

enableDD: true

All leaf nodes have the following configuration:

allowDrop: true,
draggable: true

All folders are set to:

allowDrop: true,
draggable: false

The conclusion is, that I have chosen to override some of the builtin drag'n'drop methods in the treepanel while still maintaining the builtin functionality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文