你好,我有一个像父母和孩子一样的数据循环,如何转换成dabeng格式https://codepen.io/dabeng/post/orgchart?我有这样的:
$data_cst = array();
foreach($list as $row){
$data = array(
'name' => $row->nama,
'title' => $row->posisi,
'relationship' => $row->atasan
);
array_push($data_cst, $data);
}
echo json_encode($data_cst);
最佳答案
像这样转换你的数组
$data_cst = array("nama" => "lalit", "posisi" => "mohan","atasan" =>
"chawla","children" => [array("nama" => "lalit", "posisi" =>
"mohan","atasan" => "chawla" )]);
echo json_encode($data_cst);
使用此解析器查看结果
parser
这对你有帮助
$data_cst = array();
foreach($list as $row){
$data = array(
'name' => $row->nama,
'title' => $row->posisi,
'relationship' => $row->atasan,
'children' => [$row->children]
);
array_push($data_cst, $data);
}
echo json_encode($data_cst);
关于javascript - dabeng组织结构图PHP Mysql Ajax,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48861330/