我有一个带有 https://github.com/mjsarfatti/nestedSortable 的 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")
}
}
});
});
正如你在图片中看到的,当我保存导航时,所有的 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/