0

I don't know how to recognize sortable from which item comes. It is two sortables and one draggable. Two sortables are connected to each other and draggable could be dragged into the lists. I need to recognize from which list item comes. http://jsfiddle.net/qAS93/

<ul>
    <li id="draggable" class="ui-state-highlight">Drag me down</li>
</ul>
<ul class="sortable">
    <li class="ui-state-default">Item 1</li>
    <li class="ui-state-default">Item 2</li>
    <li class="ui-state-default">Item 3</li>
    <li class="ui-state-default">Item 4</li>
    <li class="ui-state-default">Item 5</li>
</ul>
<ul class="sortable">
    <li class="ui-state-default">Item 1</li>
    <li class="ui-state-default">Item 2</li>
    <li class="ui-state-default">Item 3</li>
    <li class="ui-state-default">Item 4</li>
    <li class="ui-state-default">Item 5</li>
</ul>

$(".sortable").sortable({
    connectWith: ".sortable",
    revert: true,
    receive: function(){
        $('#text').text('I don't know from which list item comes');
    }
});

$("#draggable").draggable({
    connectToSortable: ".sortable",
    helper: "clone",
    revert: "invalid"
});
4

1 回答 1

1

您可以知道项目从哪里被拖动(或发送)。它在 item.sender 属性中

对于可排序,它是元素的父元素,对于可拖动,它是元素本身

receive: function(ui, item){
    console.log('item parent',item.sender);
    if($(item.sender).hasClass('draggable')){
        var parent = $(item.sender).parent();
    }
    else{
        var parent = item.sender;
    }

    console.log('parent', parent);
}

这是更新的小提琴

于 2013-08-10T06:42:02.117 回答