JsTree with dnd plugin, always copy

末鹿安然 提交于 2019-12-19 09:39:47

问题


I have 2 trees using jsTree and dnd plugin.
I want that each drag operation to be a copy instead of a move.
There is a "copy_modifier" which works Ok when pressing a modifier key, but I want copy to be the default behavior without the modifier. Any ideas?

Thanks,
Adrian


回答1:


Found a solution on http://groups.google.com/group/jstree
I added the following section when configuring jsTree:
"crrm": { "move": { "always_copy": "multitree" } }

Hope this helps,
Adrian




回答2:


Adrian's solution won't work with the new versions. There's that dnd plugins always copy flag dnd.always_copy

Setting this flag will make all drag and drops copy operations instead of move. But if you are looking for a solution where you need internal tree elements to be moved on dnd but inter tree dnds to be copies than here's a hack:

  • Keep a global variable flag on your page

  • Handle copy_node.jstree events and update your global flag from data.is_multi (data is the second arg of the event function)

  • Implement check_callback function and if operation is delete_node and your flag is set unset your flag and return false, preventing deletion from the dnd.




回答3:


another solution for the new version. it works, but not fully tested.

"core": {
    "check_callback": function (operation, node, node_parent, node_position, more) {
        if (more) {
            if (more.is_multi) {
                more.origin.settings.dnd.always_copy = true;
            } else {
                more.origin.settings.dnd.always_copy = false;
            }
        }
        return true;
    }
}


来源:https://stackoverflow.com/questions/3734680/jstree-with-dnd-plugin-always-copy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!