javascript - Jquery nestedSortable 所有 parent 首先都是空的

标签 javascript jquery html css nested

nestedSortable screenShot

我有一个带有 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")
            }
        }
    });
});

正如你在图片中看到的,当我保存导航时,所有的 parent 都是空的。
仅当我重新排序导航并保存它们时它才有效。

如何打印导航并将默认排序更新为 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>

关于javascript - Jquery nestedSortable 所有 parent 首先都是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43078648/

相关文章:

javascript - 如何在javascript中将函数作为参数传递

coldfusion - 如何使用 jQuery 通过 ajax 将数组变量发送到 ColdFusion CFC 远程方法?

javascript - 汉堡菜单下拉低宽度

java - Jsoup 选择其子元素不包含特定标记的元素

javascript - 有什么方法可以在 Javascript 中的 ul 和 ol 之间切换?

javascript - 将绑定(bind)应用于整个 dom 或每个需要它的单独元素?

javascript - TypeError : require(. ..).listen 不是函数

javascript - 为什么angularJS将空格视为空?

javascript - 为日期时间选择器设置 slider 的默认值

html - 使用html在listview中排列 "list items"