我正在使用 jquery Nestable ( http://dbushell.github.io/Nestable/ )。
当我更改可嵌套元素的顺序时,我试图从中截取数据。
$('.dd').nestable().on('change', function() {
var json_text = $('.dd').nestable('serialize');
$.post("/includes/processes/core.php", {
cmd: 'nestable',
table: table,
data: json_text
}, function(response){
alert(response);
});
});
在 core.php 我已经完成了:
$data = $_POST['data'];
$data = json_decode($data, true);
function parseJsonArray($jsonArray, $parentID = 0) {
$return = array();
foreach ($jsonArray as $subArray) {
$returnSubSubArray = array();
if (isset($subArray['children'])) {
$returnSubSubArray = parseJsonArray($subArray['children'], $subArray['id']);
}
$return[] = array('id' => $subArray['id'], 'parentID' => $parentID);
$return = array_merge($return, $returnSubSubArray);
}
return $return;
}
$readbleArray = parseJsonArray($data);
比我必须操纵这个数组,但我不能继续,因为响应是:
"json_decode() expects parameter 1 to be string, array given in core.php on line (where is "$data = json_decode($data, true;")"
如果我用 json_encode($data) 更改 json_decode($data, true) 这是响应:
"Invalid argument supplied for foreach() in core.php on line (where is "foreach ($jsonArray as $subArray);")"
请帮我..