jQuery:可排序嵌套但不连续

时间:2012-03-24 10:16:10

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

我正在本地开发这个页面,所以不幸的是我无法展示一个例子,但我有两个“list”构建的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拖动了。

我看到的所有插件都假设元素在下一个元素之后就是一个。

对此有何想法?

1 个答案:

答案 0 :(得分:0)

在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
        )

最重要的是,删除最后一行的评论。