【问题标题】:Sortable item moved from one list to another, loses handle and sort capability可排序项目从一个列表移动到另一个列表,失去句柄和排序功能
【发布时间】:2009-07-21 15:52:10
【问题描述】:

我有带有 OL>LI 列表的 DIV,每个列表都是可排序的,我将它们连接在一起,以便用户可以将 LI 从一个列表移动到另一个列表。似乎是一件很常见的事情。

当可排序列表收到一个项目时,该项目将失去其“可排序性”..或者至少句柄无法处理它。

这里有一些代码向您展示我如何设置可排序列表:

$(".sortable").sortable({
  connectWith: ".sortable",
  revert: true,
  opacity: 0.5,
  handle: $('.sample_view_image span img'),
  cursor: 'move',
  receive: function(event, ui) {
    $(ui.item).formatSampleToGallery();
    $(ui.item).sortable("refresh"); //thought this would reconnect everything
  }
});

【问题讨论】:

    标签: jquery jquery-ui jquery-ui-sortable


    【解决方案1】:

    首先,我引用了 $(ui.item) ,它一开始是不可排序的。呵呵。

    其次,当我使用正确的选择器 $(ui.item).parent() 时,“刷新”仍然没有正确地重新建立“句柄”。似乎“刷新”应该为我解决这个问题,我是不是在滥用它?!

    我不得不使用下面的代码让它正常工作,感觉有点脏……:

    $(".sortable").sortable({
      connectWith: ".sortable",
      revert: true,
      opacity: 0.5,
      handle: $('.sample_view_image span img'),
      cursor: 'move',
      receive: function(event, ui) {
        $(ui.item).formatSampleToGallery();
    
        $(ui.item).parent().sortable({
          connectWith: ".sortable",
          revert: true,
          opacity: 0.5,
          handle: $('.sample_view_image span img'),
          cursor: 'move'
        });
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 2020-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多