JsTree v3.0 drag and drop plugin. Reference target node upon dropping

后端 未结 8 926
南笙
南笙 2021-01-12 09:30

I use drag and drop plugin of jsTree library (ver. 3.0) With the following code I can bind to the end of drag\'n\'drop action, but I can not see a way to get the reference t

8条回答
  •  盖世英雄少女心
    2021-01-12 10:24

    Bind the listener after document is ready:

    $(document).ready(function() {
        $(document).on('dnd_stop.vakata', function (e, data) {
            let ref = $.jstree.reference("#jstree");
            let nodes = data.data.nodes.map(node_id => ref.get_node(node_id));
            let parent_node_id = nodes[0].parent;
            let parent = ref.get_node(parent_node_id);
        });
    });
    

    jstree has an internal listener for dnd_stop.vakata.jstree that performs the ui logic. It's setup inside a $(function() {...}) i.e. when the document is ready. If you bind your custom function before jstree, you get the parent before the ui logic is executed.

提交回复
热议问题