jQuery UI sorting some elements of nested list

对着背影说爱祢 提交于 2019-12-11 17:07:31

问题


In the following jsFiddle, there consists of a phase, week, day.

The idea is that:
1) Phase can be moved above or below other phases
2) Weeks can only be moved between phases (if there are nested days, they'll move with the parent week)
3) Days can be moved into other weeks

As I have it right now, you can move a Week but the Days beneath it do not follow and can become orphaned (bad). The other issue I'm running into is if you move a Day 1 into another week that also has a Day 1, something breaks, the second Day 1 can no longer be moved, it moves the entire Phase grouping (duplicates are okay).

I could really use some help with configuring the sortable options.

$( "#listContainer ul" ).sortable(
{
  /* connectWith: ".group", */
  placeholder: "itemPlaceholder",
  cursor: 'move'
  }
);

$('.group').sortable({
  items: "> div.listItem",
  //    connectWith: ".srtable, .group",
  connectWith: false,
  receive: function( event, ui ) {
    //alert('receive');
    //console.log(ui);
    //console.log(ui.item)
    //console.log($(ui.item).attr('class'))
    if ($(ui.item).hasClass('phaseTitle')) {
      $(ui.sender).sortable("cancel");
      alert('Sorry! Phases cannot be nested');
    }

  }
});

$('.days').sortable({
  connectWith: ".group"
})

来源:https://stackoverflow.com/questions/54016071/jquery-ui-sorting-some-elements-of-nested-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!