在 droppable 的 Drop 事件中调用 $(item).sortable('cancel') 将禁用 sortable。

7

我有一些可排序的连接列表,同时也是可放置的位置。问题在于,当我在可放置事件的drop中调用sortable的cancel方法时,sortable被破坏了,不再工作。 例如http://jsfiddle.net/zSnBA/10/ ,尝试移动第二个列表中的编号102的div:您将看到调用取消事件,但可排序功能将无法正常工作。 有什么帮助吗?

1个回答

6

我建议不要将可排序列表也设为可拖动,而是监听可排序列表的receive事件来取消事件:

$('div.products-list').sortable({
    connectWith: '.products-list',
    placeholder: 'ui-state-highlight',
    items: 'div.product',
    revert: 200,
    receive: function(event, ui) {
        var prod_id = ui.item.attr("prod_id");

        /* Equal to 1 is valid because an item was just added to the list: */
        if ($(this).find(".product[prod_id='" + prod_id + "']").length > 1) {
            ui.sender.sortable("cancel");
        }
    }
});

Example: http://jsfiddle.net/z5X5y/


1
我尝试过这个,但是我不能使用它,因为接收触发器仅在将项目从一个列表移动到另一个列表时触发。我需要它始终触发。 - albanx
@albanx:所以您需要在项目在其当前列表中移动时触发它? - Andrew Whitaker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接