我有一个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?
最佳答案
不确定这是否有帮助,但我认为您的标记略有错误。尝试以下方法:
<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>