javascript - jstree 3 get the position where the target got dropped - Stack Overflow

I have created thisjQuery(function($) {$(document).on('dnd_stop.vakata', function(e, data) {

I have created this

/

jQuery(function($) {
    $(document).on('dnd_stop.vakata', function(e, data) {
        var origin = $(data.element);
        var target = $(data.event.target);
        // Missing something here to get if the origin is before or after the target

        $('#result').html(
            '<div><b>Target:</b> ' + target.html() + '</div>' + 
            '<div><b>Origin:</b> ' + origin.html() + '</div>'
        );
    })

    $('#jstree_demo').jstree({
      "core" : {
        "check_callback" : true,
        "themes" : { "stripes" : true },
      },
      "plugins" : [
        "dnd"
      ]
    });
});

Now if I move fx 1-5 to the top, the target is 1-1 but if I move fx 1-5 to the bottom, the target is 1-8

Is there any method where I can find out if the origin is before or after the target?

I have created this

http://jsfiddle/n82vvvo6/

jQuery(function($) {
    $(document).on('dnd_stop.vakata', function(e, data) {
        var origin = $(data.element);
        var target = $(data.event.target);
        // Missing something here to get if the origin is before or after the target

        $('#result').html(
            '<div><b>Target:</b> ' + target.html() + '</div>' + 
            '<div><b>Origin:</b> ' + origin.html() + '</div>'
        );
    })

    $('#jstree_demo').jstree({
      "core" : {
        "check_callback" : true,
        "themes" : { "stripes" : true },
      },
      "plugins" : [
        "dnd"
      ]
    });
});

Now if I move fx 1-5 to the top, the target is 1-1 but if I move fx 1-5 to the bottom, the target is 1-8

Is there any method where I can find out if the origin is before or after the target?

Share Improve this question asked Dec 3, 2014 at 13:16 Martin-Martin- 9272 gold badges13 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

This may be a little different then your direct question but this is how I solved the issue of figuring out the position of the drop. After the 'dnd_stop.vakata' is called the 'move_node.jstree' event is called which does contain the item being moved, old parent, new parent, and index point the item is to be dropped.

$('#AdminTree').on("move_node.jstree", function (e, data) {

        //item being moved                      
        var moveitemID = $('#' + data.node.id).find('a')[0].id;            

        //new parent
        var newParentID = $('#' + data.parent).find('a')[0].id;

        //old parent
        var oldParentID = $('#' + data.old_parent).find('a')[0].id;

        //position index point in group
        //old position
        var oldPostionIndex = data.old_position;
        //new position
        var newPostionIndex = data.position;
    });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745324147a4622578.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信