我有可排序的列表,我需要在某些情况下防止掉线,这取决于我在放弃时“推开”的内容。这是一些sorta-pseudo代码:
$('ul#SortableList').sortable( {connectWith: 'ul#OtherList',
beforeStop: function(ev, ui) {
// Need item(s) that are being "pushed" out of the way of the item being dropped
if (adjacentItem == condition)
{ // prevent the drop
$(this).sortable("cancel");
}
我知道“这个”会给我实际的列表本身,但我不知道如何让实际的项目被丢弃......或者甚至只是一个特定的项目之前或之后会让我走上正确的轨道。
弄清楚了:
beforeStop: function(ev, ui)
var previousItem = ui.placeholder.parent().children().get(ui.placeholder.index() - 2); // 2 works here, probably because the placeholder AND the dropped item are counted
console.log(previousItem);
console.log(ui.placeholder);
var nextItem = ui.placeholder.parent().children().get(ui.placeholder.index() + 1);
console.log(nextItem);
console.log(ui.placeholder.parent());
}