【问题标题】:jQuery: Sortable nested but not continuousjQuery:可排序嵌套但不连续
【发布时间】:2012-03-24 10:16:10
【问题描述】:

我正在本地开发页面,所以很遗憾我无法展示示例,但我有两个 jQuery mobile 的“列表”构建。

我希望两个列表都可以使用 jquery ui 插件进行排序。

它可能看起来像这样:

<div class="sortable"> //1st sortable wrapper
  <div> //list item for 1st sortable wrapper
    <div>
     <div>
       <div class="sortable"> //2nd sortable list wrapper
         <div> //list item for 2nd sortable wrapper

那我打个电话

jQuery(".sortable").sortable()

所以我基本上有两个独立的可排序对象。第一组可排序对象中的一组可排序对象。每个分组都应该独立于另一组可排序对象。

将第二组可排序元素动态添加到页面可能毫无价值。

添加后,我正在调用

jQuery(".sortable").sortable('refresh')

无济于事,动态添加的第二组可排序元素永远无法排序。当我尝试拖动它们时,父级 .sortable 会改为拖动。

我看到的所有插件都假设元素是一个紧接着一个。

对此有什么想法吗?

【问题讨论】:

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


    【解决方案1】:

    在jQuery-ui-sortable文件开发版中。

    有一句话说明了这一点:

    改变:

    if(itemElement != this.currentItem[0] //cannot intersect with itself
                &&  this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
                &&  !$.ui.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
                && (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], itemElement) : true)
                //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
            )
    

    到:

    if(itemElement != this.currentItem[0] //cannot intersect with itself
                &&  this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
                &&  !$.ui.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
                && (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], itemElement) : true)
                && itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
            )
    

    基本上,删除最后一行的注释。

    【讨论】:

      猜你喜欢
      • 2011-02-18
      • 2016-05-15
      • 2018-03-25
      • 2010-10-31
      • 1970-01-01
      • 2012-06-01
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多