jQuery EasyUI 树形菜单 - 创建异步树形菜单
为了创建异步的树形菜单(Tree),每一个树节点必须要有一个 &qpos;id&qpos; 属性,这个将提交回服务器去检索子节点数据。

创建树形菜单(Tree)
<ul id="tt" class="easyui-tree" url="tree2_getdata.php"> </ul>
服务器端代码
$id = isset($_POST[&qpos;id&qpos;]) ? intval($_POST[&qpos;id&qpos;]) : 0; include &qpos;conn.php&qpos;; $result = array(); $rs = mysql_query("select * from nodes where parentId=$id"); while($row = mysql_fetch_array($rs)){ $node = array(); $node[&qpos;id&qpos;] = $row[&qpos;id&qpos;]; $node[&qpos;text&qpos;] = $row[&qpos;name&qpos;]; $node[&qpos;state&qpos;] = has_child($row[&qpos;id&qpos;]) ? &qpos;closed&qpos; : &qpos;open&qpos;; array_push($result,$node); } echo json_encode($result); function has_child($id){ $rs = mysql_query("select count(*) from nodes where parentId=$id"); $row = mysql_fetch_array($rs); return $row[0] > 0 ? true : false; }