jQuery UI sortable - 获取与 drop 相邻的项目

jQuery UI sortable - get items adjacent to a drop

我有可排序的列表,在某些情况下我需要防止删除,这取决于我 "pushing aside" 删除时的内容。这是一些伪代码:

    $('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");
                              }

我知道 "this" 会给我实际的列表本身被拖放到上面,但我不知道如何让实际的项目被拖放到......或者甚至只是一个特定的之前或之后会让我走上正轨。

想通了:

    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());
                          }