@author YHC
创建异步的tree,每一个tree几点必须要有一个'id'属性 ,这个将提交回服务器去检索子节点数据.

创建 Tree
<ul id="tt" class="easyui-tree"
url="tree2_getdata.php">
</ul>
服务器端代码
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
include 'conn.php';
$result = array();
$rs = mysql_query("select * from nodes where parentId=$id");
while($row = mysql_fetch_array($rs)){
$node = array();
$node['id'] = $row['id'];
$node['text'] = $row['name'];
$node['state'] = has_child($row['id']) ? 'closed' : 'open';
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;
}
本文介绍如何使用EasyUI创建异步加载子节点数据的Tree组件。通过定义特定的HTML结构和服务器端PHP脚本来实现Tree的数据异步加载功能。
133

被折叠的 条评论
为什么被折叠?



