Jquery nestedSortable所有父项在第一个地方都为空

时间:2017-03-28 19:51:19

标签: javascript jquery html css nested

nestedSortable screenShot

我有nestedSortable导航https://github.com/mjsarfatti/nestedSortable,这是我的代码:

<ol class="productSort navSortable">
    @foreach($navigations as $item)
        <li data-id="{{ $item['id'] }}">
            <div>{{ $item['id']." - ".$item['name'] }}</div>
        </li>
        @if($item->children->count() > 0)
          <ol>
            @foreach($item->children as $child)
                <li data-id="{{ $child['id'] }}" id="{{ "list_".$child['id'] }}">
                    <div>{{ $child['id']." - ".$child['name'] }}</div>
                </li>
            @endforeach
          </ol>
        @endif
    @endforeach
</ol>
$('.navSortable').nestedSortable({
    handle: 'div',
    items: 'li',
    toleranceElement: '> div',
    isTree: true,
    maxLevels:2,
    forcePlaceholderSize: true,
    handle: 'div',
    helper: 'clone',
    items: 'li',
    opacity: .6,
    placeholder: 'placeholder',
    revert: 250,
    tabSize: 25,
    tolerance: 'pointer',
    expandOnHover: 700,
    startCollapsed: true
});

$("#saveSortNav").click(function () {
    var navsort = $('.navSortable').nestedSortable('serialize');
    console.log($('.navSortable').nestedSortable('serialize'));
    $.ajax({
        method: 'POST',
        url: "/dashboard/navigations/sortStore",
        data: { sortData: navsort }
    }).done(function (data, textStatus, xhr) {
        if (xhr.status == 200) {
            data = JSON.parse(data);
            if (data.status == 1) {
                swal("انجام شد !", "تغییرات با موفقیت ثبت گردید", "success")
            } else {
                swal("خطا !", "خطایی در ثبت پیش آمده است لطفا بعدا دوباره تلاش نمایید", "error")
            }
        }
    });
});

如图所示,当我保存导航时,所有父母都是空的 它仅在重新排序导航并保存时才有效。

如何打印导航并将默认排序更新为nestedSortable?

1 个答案:

答案 0 :(得分:0)

不确定这是否会有所帮助,但我认为您的标记稍有不妥。试试这个:

<ol class="productSort navSortable">
  @foreach($navigations as $item)
    <li data-id="{{ $item['id'] }}">
      <div>{{ $item['id']." - ".$item['name'] }}</div>
      @if($item->children->count() > 0)
        <ol>
          @foreach($item->children as $child)
            <li data-id="{{ $child['id'] }}" id="{{ "list_".$child['id'] }}"><div>{{ $child['id']." - ".$child['name'] }}</div></li>
          @endforeach
        </ol>
      @endif
    </li>
  @endforeach
</ol>