我有可排序的列表,在某些情况下,我需要防止删除,具体取决于删除时我要“抛开”的内容。这是一些伪代码:

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

关于jquery - jQuery UI可排序-获取与拖放相邻的项目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55876546/

10-11 08:24