EasyUI 异步Tree
用etmvc framework返回json数据。
创建HTML标记
<ul id="tt"></ul>
创建jQuery代码
我们使用url属性来指向远程数据
$('#tt').tree({
url:'/demo2/node/getNodes' // The url will be mapped to NodeController class and getNodes method
});
数据模型
@Table(name="nodes")
public class Node extends ActiveRecordBase{
@Id public Integer id;
@Column public Integer parentId;
@Column public String name;
public boolean hasChildren() throws Exception{
long count = count(Node.class, "parentId=?", new Object[]{id});
return count > 0;
}
}
写控制代码
如果node是子,记住设置node状态为closed。
public class NodeController extends ApplicationController{
/**
* get nodes, if the 'id' parameter equals 0 then load the first level nodes,
* otherwise load the children nodes
* @param id the parent node id value
* @return the tree required node json format
* @throws Exception
*/
public View getNodes(int id) throws Exception{
List<Node> nodes = null;
if (id == 0){ // return the first level nodes
nodes = Node.findAll(Node.class, "parentId=0 or parentId is null", null);
} else { // return the children nodes
nodes = Node.findAll(Node.class, "parentId=?", new Object[]{id});
}
List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();
for(Node node: nodes){
Map<String,Object> item = new HashMap<String,Object>();
item.put("id", node.id);
item.put("text", node.name);
// the node has children,
// set the state to 'closed' so the node can asynchronous load children nodes
if (node.hasChildren()){
item.put("state", "closed");
}
items.add(item);
}
return new JsonView(items);
}
}
数据配置实例
domain_base_class=com.et.ar.ActiveRecordBase
com.et.ar.ActiveRecordBase.adapter_class=com.et.ar.adapters.MySqlAdapter
com.et.ar.ActiveRecordBase.driver_class=com.mysql.jdbc.Driver
com.et.ar.ActiveRecordBase.url=jdbc:mysql://localhost/mydb
com.et.ar.ActiveRecordBase.username=root
com.et.ar.ActiveRecordBase.password=soft123456
com.et.ar.ActiveRecordBase.pool_size=0
部署
· 建立MySQL数据库
· 从'/db/item.sql'导入测试表数据,表名是'item'.
· 按需要改变数据库配置,配置文件在/WEB-INF/classes/activerecord.properties中。
· 运行程序
EasyUI 异步Tree的更多相关文章
- easyui 异步json tree跨域访问问题解决
最近在用easyui中的异步tree时发现了跨域访问问题,我们都知道jquery ajax提供get请求的跨域访问.所以解决easyui tree跨域访问的问题便是将数据通过jquery ajax将数 ...
- 第二百二十六节,jQuery EasyUI,Tree(树)组件
jQuery EasyUI,Tree(树)组件 本节课重点了解 EasyUI 中 Tree(树)组件的使用方法,这个组件依赖于 Draggable(拖 动)和 Droppable(放置)组件. 一.加 ...
- easyUI 的tree 修改节点,sql递归查询
1.easyUI 的tree 修改节点: 我需要:切换语言状态,英文下, 修改根节点文本,显示英文. 操作位置:在tree的显示 $('#tree').tree(),onLoadSuccess事件方法 ...
- easyui中tree控件添加自定义图标icon
来源于:http://blog.163.com/lintianhuanhai@126/blog/static/165587366201421704420256/ <!DOCTYPE html&g ...
- 做权限树时 使用EasyUI中Tree
符合EasyUI中Tree的Json格式,我们先看一下,格式是如何的 [{ "id":1, "text":"My Documents", & ...
- 如何让EasyUI的Tree或者ComboTree节点不显示图标?
版本:jQuery EasyUI 1.3.2 通过测试,只需把节点的state属性设置为null即可使EasyUI的Tree或者ComboTree控件的节点不显示图标.
- easyUI的tree
前端使用easyUI,放了一个tree,搞死了. easyUI的tree,后端传过来的数据,是json格式:然后easyUI向后端提交.请求时,会自动将节点的id附在url后面. 主要有两个注意的地方 ...
- 使用EasyUI中Tree
easyui里面的加载tree的两种方式 第一种: 使用EasyUI中Tree 符合EasyUI中Tree的Json格式,我们先看一下,格式是如何的 [{ , "text":&qu ...
- jquery easyui的异步tree
1.创建一个简单的tree 结果如图: <script> $(function(){ $('#tt').tree(){ url:'要提交的url地址', checkbox:true, li ...
随机推荐
- iOS socket Stream 服务器端 及 客户端 演示
iOS socket Stream 测试环境,mac osx 10.8 一:建立服务器端 由于mac osx10.8 已经集成 python2和 Twisted,我们可以直接利用此,构建一个简单的so ...
- iOS-字符串拼接
// // main.m // /* 将两个字符串 NSString * str1 = @"123"; NSString * str2 = @"abc"; 拼接 ...
- 【Linux】head命令
用途 它是用来显示开头或结尾某个数量的文字区块 全称 head的全称即为head 参数 -q :隐藏文件名 -v :显示文件名 -c :<字节>显示字节数 -n :<行数>显示 ...
- 18-spring学习-利用Annotation配置AOP
之前是通过配置完成aop操作,如果自己写的话,太麻烦了,可以使用基于annotation的配置完成. 第一步:打开AOP的annotation支持 加上一句话: <context:annotat ...
- Android系统示例之ActionBarCompat
导入工程ActionBarCompat时,出现错误.从其他工程下拷贝project.propertiest文件过来,问题仍在.拷贝后需要重启Eclipse才解决.问题如下: [2013-07-03 1 ...
- 关闭mysql慢查询日志
开启mysql慢日志 MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记录在MySQL中响应时间超过阀值的语句,具体指运行时间超过long_query_time值的SQL,则会被记录到慢查 ...
- JS中的转义字符
http://www.cnblogs.com/wangpei/archive/2009/05/09/1453260.html \b 退格 \t TAB,水平 \v ...
- 简单hello world
第一步配置路由: 打开app/http/route.php文件,输入:Route::get('/home', 'HomeController@index'); 第二步配置控制器: 控制文件可以手动添加 ...
- EMQ学习 ---集群
emqttd集群设置管理 一.先来看EMQ的文档定义:http://emqtt.com/docs/v1/cluster.html emqttd集群设置管理 假设部署两台服务器s1.emqtt.io, ...
- Android 添加新的Activity
1.右键, New一个Class ,文件名如:ParaSetActivity.java 注: Superclass要选择android.app.Activity ,没有直接写入android.app. ...