gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:48:04 25 4
gpt4 key购买 nike

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

第一 required 功能非常简单,只是内置的拖放功能仅与单个树隔离。

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com