jstree move, drag and drop

前端 未结 3 773
暗喜
暗喜 2021-02-02 17:26

I want to implement the move functionality for a node in jstree. Is it the move that needs to be implemented or the drag and drop? Also, it would be nice to have working code f

3条回答
  •  忘掉有多难
    2021-02-02 17:58

    The above approaches do not work with the latest versions of jstree (3.3.7 as of today).

    The first line of Bojin's answer still holds true. To implement rules, you can use core.check_callback or possibly, the types plugin; the crrm plugin doesn't exist anymore. Bind to move_node.jstree to perform some action on completion of move (drop). By default, the dnd plugin allows re-ordering (dropping between two nodes) and copying (Ctrl + drag), in addition to moving a node. The code snippet below shows how to disable these additional behaviors.

    $('#treeElement').jstree({
        'core': {
            'check_callback': CheckOperation,
            ...
        },
        'plugins': ['dnd']
    })
    .bind("move_node.jstree", function(e, data) {
        //data.node was dragged and dropped on data.parent
    });
    
    function CheckOperation(operation, node, parent, position, more) {
        if (operation == "move_node") {
            if (more && more.dnd && more.pos !== "i") { // disallow re-ordering
                return false;
            }
            ... more rules if needed ...
            else {
                return true;
            }
        }
        else if (operation == "copy_node") {
            return false;
        }
        return true;
    }
    

提交回复
热议问题