簡體   English   中英

jQuery nestedSortable的所有父代在第一位都為null

[英]Jquery nestedSortable all parents are null at first place

nestedSortable屏幕截圖

我有一個https://github.com/mjsarfatti/nestedSortablenestedSortable導航,這是我的代碼:

<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?

不確定這是否有幫助,但我認為您的標記略有錯誤。 嘗試以下方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM