可排序+可拖动的演示-如何访问已删除的项目? [英] sortable + draggable demo - how to get access to dropped item?

查看:73
本文介绍了可排序+可拖动的演示-如何访问已删除的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可排序的列表.当新项目(从可拖动对象)放入列表时,我想获得对其执行一些操作的权限.这就是我所拥有的:

I have a sortable list. When a new item is dropped into the list (from a draggable), I'd like to get access to it to perform some operations on it. This is what I have:

$("#mySortableList").sortable({
    receive: function(event, ui) {
        alert("this is the dropped item: " + ui.item.toString());
    }
}).disableSelection();

因此,"ui.item"是被删除的元素,但现在不是重复项,这将成为我的列表的一部分.我如何访问已删除的新项目?我在这里使用来自jquery-ui站点的确切演示: http://jqueryui.com/demos/draggable/#sortable

so "ui.item" is the element that was dropped, but it's not the duplicated item that will now be part of my list. How do I get access to the new item that was dropped? I am using the exact demo from the jquery-ui site here: http://jqueryui.com/demos/draggable/#sortable

谢谢

推荐答案

您可以在stop事件中获取该项目,并检查它是否来自可拖动对象(它没有连接手柄,如果没有是来自可排序的),就像这样:

You can get the item in the stop event and check that it came from the draggable (it doesn't have a handle attached, which it would if it was from the sortable), like this:

$("#mySortableList").sortable({
    stop: function(event, ui) {
    //check it wasn't here previously
    if(!ui.item.data('tag') && !ui.item.data('handle')) {
        ui.item.data('tag', true); //tag new draggable drops
        alert("this is the dropped item: " + ui.item.toString());
    }
}).disableSelection();

您可以在此处看到要播放/测试的演示,因为未添加手柄,至少在某种程度上不重要,我们正在标记从可拖动对象中放下的项目,以使它们在移入可排序对象内时不会再次触发警报.

You can see a demo to play/test with here, since a handle doesn't get added, at least not in a way that matters, we're tagging items dropped from the draggable so that they won't fire the alert again when moved inside the sortable.

这篇关于可排序+可拖动的演示-如何访问已删除的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆