我已经使用手风琴构建了一个父子系统。结构如下

parent1
  child1
  child2
  child3
parent2
  child4
  child5
  child6
parent3
  child7
  child8
  child9


我还添加了拖放功能。我的要求是我不希望将孩子从当前的父母中拖出。它只能在当前父级中拖动和替换。例如,孩子1,2和3的位置可以与拖动互换,但孩子2不应进入parent2和parent3内。另外,不应该允许parent2子级拖动parent1和parent2

我进行了一项研究,发现手风琴提供了一种财产收容措施:parent,但是它不能正常工作。谁能帮我解决这个问题?

<div id="available_fields_container" class="accordion list_container ui-sortable active" data-accordion="one">
  <dd class="accordion-navigation active" id="data_download_fields">
    <a href="#data_download_fields">
      <b>FootBall Fields</b>
      <span class="collapse-symbol"></span>
    </a>
    <span class="select-group" data-fields="#data_download_fields">Select all</span>
    <div id="data_download_fields" class="content active" data-group="FootBall Fields">

      <div class="field_items"  data-index="4" data-group="FootBall Fields">
        Andrew
        <span class="plus-icon action-icon">+</span>
        <i class="icon-cross2 action-icon"></i>
      </div>
      <div class="field_items"  data-index="5" data-group="FootBall Fields">
        Sam
        <span class="plus-icon action-icon">+</span>
        <i class="icon-cross2 action-icon"></i>
      </div>

    </div>
  </dd>

    <dd class="accordion-navigation " id="data_download_hockey_fields">
      <a href="#data_download_hockey_fields">
        <b>hockey Fields</b>
        <span class="collapse-symbol"></span>
      </a>
      <span class="select-group" data-fields="#data_download_hockey_fields">Select all</span>
      <div id="data_download_hockey_fields" class="content " data-group="hockey Fields">
          <div class="field_items"  data-index="0" data-group="hockey Fields">
  jason
    <span class="plus-icon action-icon">+</span>
    <i class="icon-cross2 action-icon"></i>
  </div>
  <div class="field_items"  data-index="1" data-group="hockey Fields">
  Jane
    <span class="plus-icon action-icon">+</span>
    <i class="icon-cross2 action-icon"></i>
  </div>

      </div>
    </dd>

</div>

最佳答案

为了实现这些类型的事情,您可以使用jquery可排序的回调。
就您而言,您将需要启动和退出回调

var before_drag;

start: function(event, ui){
  before_drag = ui.item.parent().attr('id')
}

out: function(event, ui){
  var after_drag = ui.item.parent().attr('id')
        if(before_drag != after_drag){
          event.preventDefault();
          event.stopPropagation();
        }
}

07-26 04:35