您好我有循环中的父级和子级数据,如何转换为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);
答案 0 :(得分:0)
像这样转换你的数组
$data_cst = array("nama" => "lalit", "posisi" => "mohan","atasan" =>
"chawla","children" => [array("nama" => "lalit", "posisi" =>
"mohan","atasan" => "chawla" )]);
echo json_encode($data_cst);
使用此解析器查看结果
这会对你有所帮助
$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);