我想知道如何根据这种类型的数组更新我的数据库:
Array
(
[0] => Array
(
[id] => 58
[children] => Array
(
[0] => Array
(
[id] => 62
[children] => Array
(
[0] => Array
(
[id] => 61
)
)
)
)
)
[1] => Array
(
[id] => 60
[children] => Array
(
[0] => Array
(
[id] => 63
)
)
)
[2] => Array
(
[id] => 0
[children] => Array
(
[0] => Array
(
[id] => 59
)
)
)
)
我尝试了不同的方法,但它没有按应有的方式工作。
这是我保存列表新顺序的函数,我使用nestedSortable('toHierarchy')
function order()
{
$list = $_POST['list'];
foreach ($list as $key => $value) {
if(is_array($value['children'])) {
$i=1;
foreach($value['children'] as $k=>$v) {
$this->section->edit(array('order' => $i, 'parent_id'=>$value['id']),
"WHERE `id`=" . $v['id']);
echo 'parent '.$value['id'].'child->'.$v['id'].' order->'.$i.'<br/>';
$i++;
}
}
else {
$this->section->edit(array('order' => $key, 'parent_id'=>0),
"WHERE `id`=" . $value['id']);
}
}
}
但它不适用于超过 2 个级别的列表。
这是我正在使用的 js
$('ol.sortable').nestedSortable({
update : function () {
var orderNew = $(this).nestedSortable('serialize', {startDepthCount: 0});
//alert(orderNew);
$.ajax({
type: 'post',
url: '<?php echo (APP_URL); ?>projects/<?php echo $project_id; ?>/sections/order_list',
data: {list:orderNew}
});
},
disableNesting: 'no-nest',
forcePlaceholderSize: true,
handle: 'div',
helper: 'clone',
items: 'li',
maxLevels: 4,
opacity: .6,
placeholder: 'placeholder',
revert: 250,
tabSize: 25,
tolerance: 'move',
toleranceElement: '> div'
});