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. 【树莓派】树莓派raspi-config配置

    发现有些树莓派盒子,输入的结果和键盘的实际字符有差异,比如输入 | ,结果显示为 ~. 这是因为树莓派的键盘设置问题. 可以通过设置raspi-config进行配置: 第一次使用树莓派的时候需要进行一 ...

  2. python 网络请求类库 requests 使用

    python 网络请求类库 requests 使用 requests是 为python封装的强大 REST 操作类库 githubhttps://github.com/kennethreitz/req ...

  3. SEO优化实践操作

    合理的title.description.keywords:搜索对着三项的权重逐个减小,title值强调重点即可,重要关键词出现不要超过2次,而且要靠前,不同页面title要有所不同:descript ...

  4. android源码相关网站

    https://android.googlesource.com/ google的android源码网站 http://source.android.com/ android网站 git://code ...

  5. HBase权威指南 高清中文版 PDF(来自linuxidc)

      内容提要 <HBase权威指南>由乔治(Lars George)著,探讨了 如何通过使用与HBase高度集成的Hadoop将 HBase的可 伸缩性变得简单:把大型数据集分布到相对廉价 ...

  6. Android开发之定位系统

    2013-07-04 定位系统 全球定位系统(Global Positioning System, GPS), 又称全球卫星定位系统. 最少只需其中3颗卫星,就能迅速确定用户组地球所处的位置及海拔高度 ...

  7. cordova build android get Execution failed for task ':dexArmv7Debug'

    本篇文章由:http://xinpure.com/cordova-build-android-get-execution-failed-for-task-dexarmv7debug/ XGPush 腾 ...

  8. PHP自学,第一阶段,基础学习

    环境搭建OS X系统上 Win7执行OS X虚拟机 在 OS X上安装MAMP执行环境 IDE使用 Netbeans PHP版本号开发 数据库使用mysql 自学资料使用:PHP从入门到精通.pdf ...

  9. php 实现打印预览的功能

    <inputid="btnPrint" type="button" value="打印"onclick="javascrip ...

  10. pandas contact 之后,若要用到index列,要记得用reset_index去处理index

    # -*- coding: utf-8 -*- import pandas as pd import sys df1 = pd.DataFrame({ 'A': ['A0', 'A1', 'A2', ...