jQuery UI可排序 - 获取与drop相邻的项目

问题描述 投票:0回答:1

我有可排序的列表,我需要在某些情况下防止掉线,这取决于我在放弃时“推开”的内容。这是一些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");
                              }

我知道“这个”会给我实际的列表本身,但我不知道如何让实际的项目被丢弃......或者甚至只是一个特定的项目之前或之后会让我走上正确的轨道。

jquery user-interface jquery-ui-sortable drag
1个回答
1
投票

弄清楚了:

    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());
                          }
© www.soinside.com 2019 - 2024. All rights reserved.