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

标签 jquery user-interface jquery-ui-sortable drag

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

    $('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 UI 可排序 - 获取与 drop 相邻的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55876546/

相关文章:

javascript - 如何在控制台中隐藏日志消息的来源?

c++ - 在 QThread 中运行长时间操作并向主线程发送信号仍然会卡住 UI

javascript - 拖放可排序 ng :repeats in AngularJS?

javascript - 具有不透明度和类似模态行为的向导

php - 使用 PHP/jQuery 获取 textarea 的值

javascript - 在站点加载时运行 javascript

java - 如何绘制正弦图?

java Swing 。如何等待其他 Jframes

jQuery Sortable - 当新元素拖入列表时保存顺序

jquery可拖动非列表项到可排序列表