FancyTree:节点对象在拖动到根级别时不正确

FancyTree: Node object is incorrect when dragged to root level

本文关键字:不正确 拖动 节点 对象 FancyTree      更新时间:2023-09-26

我试图在拖放事件之后为节点定义新的父id。

假设您将节点拖动到除根之外的任何级别,此功能都可以正常工作

dragDrop: function(node, data) {
                /** This function MUST be defined to enable dropping of items on
                 *  the tree.
                 */
                data.otherNode.moveTo(node, data.hitMode);
                // Set Parent ID with id of parent
                data.otherNode.data.parent_id = node.data.id;
            }

然而,当将节点拖动到根节点时,它会从其他地方获取一个id(我还没有弄清楚模式)。

我一直在监视fancytree node.key(它显示父节点的键),当我使用tree.toDict(true)输出树时,它总是输出key_2,而从不输出根的值root_1;作用

找出节点是否已拖动到根节点的正确方法是什么?

正如mar10所提到的,您永远不会将不可见的系统根节点作为dragDrop事件的目标节点。因此,您永远无法达到0级。

节点总是被丢弃在其他节点的"上方"、"之前"或"之后",用node.hitMode表示。

如果你只是想防止将节点放入第一级(我认为这就是你所说的根级别),并且只"放入"文件夹,那么限制hitMode,比如:

dragEnter: function(node, data) {
        if(node.folder == false) {
               return false;
        }
        return 'over';
}

如果您想检查dragDrop事件中的第一个(根)级别,您可以执行以下操作:

dragDrop: function(node, data) {
        if (node.getLevel() == 1 && (data.hitMode == 'after' || data.hitMode == 'before')) {
            console.log('dropped into first level');
        }
}

如果您的问题针对其他内容,请编辑您的问题或留下评论。

这是预期的行为:

var tree = $(":ui-fancytree").fancytree("getTree");
tree.rootNode.getLevel() // == 0 (invisble system root)
tree.rootNode.getFirstChild().getLevel() // == 1 (visible top level node)

您可以删除另一个节点的beforeover(即作为的子节点)。(您永远不会将根节点作为目标,因为您看不到它)。如果您记录node.titlenode.hitModenode.getLevel(),事情可能会变得清晰。。。