easyui中的树可以从标记中建立,也可以通过指定一个URL属性读取数据建立。如果想建立一棵异步树,需要为每个节点指定一个id属性值,这样在加载数据时会自动向后台传递id参数。

<ul id="tt"></ul>

编写前台代码:

$('#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;
}
}

编写后台的控制器代码:

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

官网例子地址:http://www.jeasyui.com/tutorial/tree/tree2.php

http://www.runoob.com/jeasyui/jeasyui-tree-tree2.html

demo下载

重要的事情说三遍!!!

$('#tt').tree({
  method:"POST",
url:'/demo2/node/getNodes' // The url will be mapped to NodeController class and getNodes method
});

method一定要用POST,GET的话要在URL后面用一个变量来做时间戳处理。

method一定要用POST,GET的话要在URL后面用一个变量来做时间戳处理。

method一定要用POST,GET的话要在URL后面用一个变量来做时间戳处理。

如果这篇文章对您有帮助,您可以打赏我

技术交流QQ群:15129679

jquery easyui tree异步加载子节点的更多相关文章

  1. jquery easyui tree动态加载子节点

    1.前端tree绑定时,使用onBeforeExpand事件:当节点展开时触发加载子节点,自动会向服务端发送请求:url为绑定url,参数为当前节点id this.tree = { method: ' ...

  2. spring mvc easyui tree 异步加载树

    使用spring mvc 注解 异步加载一棵树 jsp: <ul id="orgInfoTree"></ul> $(function(){ loadOrgT ...

  3. Easyui _treegrid 动态加载子节点

    <table id="dg" class="easyui-treegrid" title="数据字典列表" data-options= ...

  4. LayUi 树形组件tree 实现懒加载模式,展开父节点时异步加载子节点数据

    LayUi框架中树形组件tree官方还在持续完善中,目前最新版本为v2.5.5 官方树形组件目前还不支持懒加载方式,之前我修改一版是通过reload重载实例方法填充子节点数据方式,因为递归页面元素时存 ...

  5. MVC4中EasyUI Tree异步加载JSON数据生成树

      1,首先构造tree接受的格式化数据结构MODEL /// <summary> /// 定义EasyUI树的相关数据,方便控制器生成Json数据进行传递 /// </summar ...

  6. (转)jQuery EasyUI Tree - TreeGrid动态加载子节点

    有时我们已经得到充分的分层树形网格(TreeGrid)的数据. 我们还想让树形网格(TreeGrid)按层次惰性加载节点. 首先,只加载顶层节点. 然后点击节点的展开图标来加载它的子节点. 本教程展示 ...

  7. 玩转Web之easyui(二)-----easy ui 异步加载生成树节点(Tree),点击树生成tab(选项卡)

    关于easy ui 异步加载生成树及点击树生成选项卡,这里直接给出代码,重点部分代码中均有注释 前台: $('#tree').tree({ url: '../servlet/School_Tree?i ...

  8. ztree异步加载树节点

    参考文档:https://www.cnblogs.com/tenWood/p/8620708.html ztree api地址:http://www.treejs.cn/v3/api.php 说明:j ...

  9. H5+JS+JQuery+ECharts实现异步加载

    这几天,看了一下ECharts官网的API和Demo发现很有意思,于是就利用模型预测产生的数据做一个伪实时的动态数据显示 . 首先,创建一个index.html的文件,我用的vscode打开的,进行编 ...

随机推荐

  1. Technical Information ARM-related JTAG / SWD / SWV / ETM Target Interfaces

    https://www.computex.co.jp/eg/products/pdf/technical_pdf/arm_if01_gijutsu_eng.pdf

  2. 0xWS2812 STM32 driver for WS2812(B) RGB LEDs

    0xWS2812 STM32 driver for WS2812(B) RGB LEDs 0xWS2812 pronounced "hex-WS2812" This code ai ...

  3. STM32F4: Generating parallel signals with the FSMC

    STM32F4: Generating parallel signals with the FSMC The goal: The memory controller can be used to ge ...

  4. Day14 自己定义泛型类的使用

    泛型的引入和体现: 问题:集合中能够存储各种类型的元素,可是由于集合能够存储各种类型数据.在获取集合中元素时,就会造成数据不安全. public class GenericDemo { public ...

  5. 使用断言NSAssert()调试程序错误

    NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异常,并切可以自定义异 ...

  6. C#编程(五十三)----------字典Dictionary<TKey,TValue>

    字典 关键字:Dicitionary 说明: 必须包含命名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由两个元组组成:键和值). 键必须 ...

  7. 丑女贝蒂第一至四季/全集Ugly Betty迅雷下载

    本季第一至四季 Ugly Betty (2006-2009)看点:<丑女贝蒂>在Betty Suarez的生命始终只有一个目标:加入到时尚行业中去.尽管要变得很聪明,工作很卖力而且要多产, ...

  8. Android之找回打包key密码的方法

    昨天准备给自己的应用发布一个新版本,在apk打包时,发现之前的用的keystore密码忘了.蛋碎了一地,我把我所能想到的密码都试了一遍(注:我平常在各个门户网站注册基本上用的都是那几个字母和数字组合做 ...

  9. NumPy-高速处理数据

    Numpy简单介绍 标准安装的Python中用列表(list)保存一组值,能够用来当作数组使用,只是因为列表的元素能够是不论什么对象,因此列表中所保存的是对象的指针.这样为了保存一个简单的[1,2,3 ...

  10. 获得手机当前的ip地址

    package com.kale.floating.net; import java.net.Inet4Address; import java.net.InetAddress; import jav ...