사용자가 직접 쿼리를 실행해야하지만 매우 쉽습니다. 트리가 예상하는 출력은 아래 예제와 같이 json 형식의 객체 배열입니다.
테이블 구조가 될 수있다 : 루트 노드를 선택 할
tree_node (ID, 제목, PARENT_ID), 그것은 나무가 완료 재귀 때까지, 어린이입니다.
function expandTree($node)
{
$result = array('text' => $node['title'], 'children' => array());
$nodes = getChildren($node); // query all nodes whose parent_id = $node['id']
foreach ($nodes as $node) {
$result['children'][] = expandTree($node);
}
return $result;
}
출력 형식 :
[
{
"text": "1. Pre Lunch (120 min)",
"expanded": true,
"classes": "important",
"children":
[
{
"text": "1.1 The State of the Powerdome (30 min)"
},
{
"text": "1.2 The Future of jQuery (30 min)"
},
{
"text": "1.2 jQuery UI - A step to richnessy (60 min)"
}
]
},
{
"text": "2. Lunch (60 min)"
},
[...]
데이터 소스 란 무엇입니까? – Younes
데이터가 데이터베이스에 있음을 의미합니다. –