JSRUN 用代码说话

创建异步树形菜单

编辑教程

jQuery EasyUI 树形菜单 - 创建异步树形菜单

本节将介绍创建异步的jQuery EasyUI树形菜单(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;
JSRUN闪电教程系统是国内最先开创的教程维护系统, 所有工程师都可以参与共同维护的闪电教程,让知识的积累变得统一完整、自成体系。 大家可以一起参与进共编,让零散的知识点帮助更多的人。
X
支付宝
9.99
无法付款,请点击这里
金额: 0
备注:
转账时请填写正确的金额和备注信息,到账由人工处理,可能需要较长时间
如有疑问请联系QQ:565830900
正在生成二维码, 此过程可能需要15秒钟