我有可排序的列表,在某些情况下我需要防止删除,具体取决于删除时我要“抛开”什么。这是一些伪代码:
$('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");
}
我知道“此”会给我实际的列表本身,但是我不知道如何将实际的项目放在它们之间……甚至只是一个特定的项目之前或之后都会使我进入正确的轨道。
答案 0 :(得分:0)
想通了:
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());
}