它就是PHPTree。
git地址:https://git.oschina.net/jiusem/PHPTree.git
或从错新站长站下载 //www.jb51.net/codes/606002.html
最简单的例子:
<?php require('PHPTree.class.php');//原始数据, 从数据库读出$data = array( array( 'id'=>1, 'name'=>'book', 'parent_id'=>0 ), array( 'id'=>2, 'name'=>'music', 'parent_id'=>0 ), array( 'id'=>3, 'name'=>'book1', 'parent_id'=>1 ), array( 'id'=>4, 'name'=>'book2', 'parent_id'=>3 ));$r = PHPTree::makeTree($data);echo json_encode($r);?>
输出:
[
{
"id": 1,
"name": "book",
"parent_id": 0,
"expanded": false, //不展开子节点
"children": [
{
"id": 3,
"name": "book1",
"parent_id": 1,
"expanded": false,
"children": [
{
"id": 4,
"name": "book2",
"parent_id": 3,
"leaf": true
}
]
新闻热点
疑难解答