【问题标题】:jQuery UI sortable - get items adjacent to a dropjQuery UI sortable - 获取与drop相邻的项目
【发布时间】:2019-09-16 11:53:12
【问题描述】:

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

    $('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】:

    想通了:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 2021-05-02
      • 1970-01-01
      相关资源
      最近更新 更多