如何访问被删除的元素

时间:2013-01-07 11:40:05

标签: jquery jquery-ui jquery-ui-sortable jquery-ui-draggable

我正在使用带有此fiddle的connectToSortable和clone选项的draggable:

var draggable_opts = {
        connectToSortable: ".sph-callout-portlet",
        helper: "clone",
        opacity: 0.75,
        revert: 'invalid',
        stop: function(event, ui) {
            // this seems to only access the original item not the clone
        }
    };

$(function() {
    $( ".sph-callout-portlet" ).sortable({
        opacity: 0.75,
        placeholder: "ui-state-highlight",
    }).disableSelection();

    $( "#sph-callout-portlet-avail li" ).draggable(draggable_opts);

});

当我删除元素时,我想获取它被放入的区域的ID或至少是元素本身。现在,根据文档draggable + connectToSortable + clone使用droppable但我找不到获取被删除元素的方法。

(上述代码最初发布在question,但有其他问题)

3 个答案:

答案 0 :(得分:1)

要获取放置它的元素,你可以这样做:

$(".sph-callout-portlet" ).sortable({
   opacity: 0.75,
   placeholder: "ui-state-highlight",
   receive: function(event, ui) {
     console.log($(this).data().sortable.element);
   }
}).disableSelection();

答案 1 :(得分:0)

您需要在可放置区域实例化droppable

$(area_selector).droppable({
    drop: function (event, ui) {
        var $area = $(this); // The droppable
        var $draggable = ui.draggable; // The draggable
    }
});

答案 2 :(得分:0)

试试这个

 $( "#sph-callout-portlet-avail li" ).droppable({
     drop: function (event, ui) {
       console.log(ui.draggable.text());
     }
 });

fiddle此处