解析jquery easyui tree异步加载子节点问题
网络编程 2021-07-04 19:20www.168986.cn编程入门
本篇文章主要介绍解析jquery easyui tree异步加载子节点问题,easyui中的树可以从标记中建立,也可以通过指定一个URL属性读取数据建立,有兴趣的可以了解一下。
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); } }
官网例子地址
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后面用一个变量来做时间戳处理。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指