从可放置区域删除可拖动项目时是否存在事件

is there an event when a draggable item is removed from a droppable area?

本文关键字:是否 事件 项目 存在 删除 区域 拖动      更新时间:2023-09-26

我有一个可放置的区域,其中包含字段名称列表(所有字段名称均可单独拖动),然后是一个带有 X 标题的表,这些标题都是可放置的,最初是空的。

有没有办法判断何时从表头中删除了项目?我正在考虑用户是否将标题从一个 TH 拖放到另一个 TH,或者如果用户将字段从 TH 拖回 fieldNamesDroppable。然后我会更新两列或一列过时的列。

当前代码:

$('#fieldNamesDroppable').droppable({
    drop: function (event, ui) {
        ui.draggable.appendTo($(this)).css({
            top: '0px',
            left: '0px'
        });
    }
});
$('th').droppable({
    drop: function (event, ui) {
        var $this = $(this);
        // if there is already an item here, cancel the drop and flash error message
        if ($this.find('.drag').length >= 1) {
            ui.draggable.draggable('option', 'revert', true);
            errorMessage("You can only add one heading to each column.");
            return;
        }
        // else, drop item
        $this.html('');
        ui.draggable.appendTo($this).css({
            top: '0px',
            left: '0px'
        });
        // update the field mappings in the controller
        updateFieldMappingsInput(ui.draggable);
    }
});

其中"updateFieldMappingsInput"更新用于跟踪标头映射的相关进程。

我相信

你想要的是 out 事件,它在 API 中描述为:

当接受的可拖动对象被拖出可拖放对象时触发 (基于公差选项)。