function print_recursive_menu2($data) { $str = ""; foreach ($data as $list) { $subchild = print_recursive_menu2($list['child']); if ($subchild != '') { $str .= '{ "text" : "' . $list['nama'] . '","id" : "' . $list['id'] . '",'; //echo '"text" : "'.$data['nama'].'","id" : "'.$data['id'].'",' ; $str .= '"children" :['; $subchild = print_recursive_menu2($list['child']); $str .= ''; $str .= $subchild; $str .= ']},'; } else { //jika tdk punya anak lg $str .= '{ "text" : "' . $list['nama'] . '","id" : "' . $list['id'] . '"},'; //$str.='{ "text" : "'.$list['nama'].'","id" : "'.$list['id'].'",'; $subchild = print_recursive_menu2($list['child']); $str .= $subchild; } } return $str; }
var UITree = function () { var handleSample3 = function () { $('#tree_3').jstree({ 'plugins': ["wholerow", "checkbox", "types"], 'core': { "themes" : { "responsive": false }, 'data': [ <?php foreach ($menu_all as $data) { echo '{'; echo '"text" : "' . $data['nama'] . '","id" : "' . $data['id'] . '",'; echo '"children" :['; echo print_recursive_menu2($data['child']); echo ' ]'; echo '},'; } ?> ] }, "types" : { "default" : { "icon" : "fa fa-folder icon-state-warning icon-lg" }, "file" : { "icon" : "fa fa-file icon-state-warning icon-lg" } } });