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的更多相关文章

  1. easyui 异步json tree跨域访问问题解决

    最近在用easyui中的异步tree时发现了跨域访问问题,我们都知道jquery ajax提供get请求的跨域访问.所以解决easyui tree跨域访问的问题便是将数据通过jquery ajax将数 ...

  2. 第二百二十六节,jQuery EasyUI,Tree(树)组件

    jQuery EasyUI,Tree(树)组件 本节课重点了解 EasyUI 中 Tree(树)组件的使用方法,这个组件依赖于 Draggable(拖 动)和 Droppable(放置)组件. 一.加 ...

  3. easyUI 的tree 修改节点,sql递归查询

    1.easyUI 的tree 修改节点: 我需要:切换语言状态,英文下, 修改根节点文本,显示英文. 操作位置:在tree的显示 $('#tree').tree(),onLoadSuccess事件方法 ...

  4. easyui中tree控件添加自定义图标icon

    来源于:http://blog.163.com/lintianhuanhai@126/blog/static/165587366201421704420256/ <!DOCTYPE html&g ...

  5. 做权限树时 使用EasyUI中Tree

    符合EasyUI中Tree的Json格式,我们先看一下,格式是如何的 [{ "id":1, "text":"My Documents", & ...

  6. 如何让EasyUI的Tree或者ComboTree节点不显示图标?

    版本:jQuery EasyUI 1.3.2 通过测试,只需把节点的state属性设置为null即可使EasyUI的Tree或者ComboTree控件的节点不显示图标.

  7. easyUI的tree

    前端使用easyUI,放了一个tree,搞死了. easyUI的tree,后端传过来的数据,是json格式:然后easyUI向后端提交.请求时,会自动将节点的id附在url后面. 主要有两个注意的地方 ...

  8. 使用EasyUI中Tree

    easyui里面的加载tree的两种方式 第一种: 使用EasyUI中Tree 符合EasyUI中Tree的Json格式,我们先看一下,格式是如何的 [{ , "text":&qu ...

  9. jquery easyui的异步tree

    1.创建一个简单的tree 结果如图: <script> $(function(){ $('#tt').tree(){ url:'要提交的url地址', checkbox:true, li ...

随机推荐

  1. centos版本7以上网卡名修改

    1.初始状态网卡 2.首先,先编辑网卡的配置文件 vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 将里面的NAME项修改为eth0 3.然后,禁 ...

  2. python3 http.client 网络请求

    python3 http.client 网络请求 一:get 请求 ''' Created on 2014年4月21日 @author: dev.keke@gmail.com ''' import h ...

  3. 苹果开发——App内购以及验证store的收据(一)

    原地址:http://zengwu3915.blog.163.com/blog/static/27834897201375105236580?suggestedreading 发了几天时间在网上折腾了 ...

  4. Burning widget

    This is a widget that we can see in Nero, K3B, or other CD/DVD burning software. #!/usr/bin/python # ...

  5. react-keeper

    通过 react-keeper 替换掉 react-router 解决 页面缓存问题.

  6. oracle 三表关联查询

      oracle 三表关联查询 CreationTime--2018年7月4日17点52分 Author:Marydon 左连接实现三表关联 表A--------------------------- ...

  7. CentOS6.5卸载默认安装的mysql5.1,并安装mysql5.5(亲测有效)

    感谢链接:https://jingyan.baidu.com/article/922554465e471a851648f4ed.html  指导. 1.安装前:CentOS6.5 yum 安装MySQ ...

  8. JS 校验,检测,验证,判断函数集合

    http://jc-dreaming.iteye.com/blog/754690 /**  *判断对象是否为空 *Check whether string s is empty.  */  funct ...

  9. EAST 自然场景文本检测

           自然场景文本检测是图像处理的核心模块,也是一直想要接触的一个方面. 刚好看到国内的旷视今年在CVPR2017的一篇文章:EAST: An Efficient and Accurate S ...

  10. maple minimax函数

    numapprox[minimax] - minimax rational approximation Calling Sequence   minimax(f, x=a..b, [m, n], w, ...