我想知道是否存在與MySQL數據的PHP樹視圖。我沒有找到適合我的項目的suitalbe。你知道是否有一些插件或代碼樣本?是否有從數據庫中的數據PHP樹視圖?
非常感謝。
編輯:
jQuery的TreeView的asyncronous例如,link text
我發現它可以工作,但我不知道如何讓source.php。你有任何想法或其他主張嗎?
我想知道是否存在與MySQL數據的PHP樹視圖。我沒有找到適合我的項目的suitalbe。你知道是否有一些插件或代碼樣本?是否有從數據庫中的數據PHP樹視圖?
非常感謝。
編輯:
jQuery的TreeView的asyncronous例如,link text
我發現它可以工作,但我不知道如何讓source.php。你有任何想法或其他主張嗎?
您需要自己運行查詢,但這很容易。樹預期的輸出是以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)"
},
[...]
假設你有父母和孩子一分貝,看看
http://www.ideashower.com/our_solutions/create-a-parent-child-array-structure-in-one-pass/ & http://www.phpriot.com/articles/nested-trees-1
一旦你有你的數據正確排序,你可以看看渲染它。
@感謝很多,這是有益的,我正在學習。 – 2010-02-03 09:58:20
什麼是您的數據源? – Younes 2010-01-22 09:23:21
我的意思是,數據來自數據庫。 – 2010-01-22 09:23:51