我正在使用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);")"


请帮我..

最佳答案

尝试删除此行,因为$ .post不执行json编码。

$data = json_decode($data, true);

09-27 21:59