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