Categories: jQuery EasyUI 教程

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

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;
 }

下载 jQuery EasyUI 实例

jeasyui-tree-tree2.zip

terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

1 天 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

1 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

3 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

3 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

4 周 ago