extjs4 异步树的写法
来源:互联网 发布:特大网络传销案判决书 编辑:程序博客网 时间:2024/05/22 08:10
<pre name="code" class="javascript">The data for this tree is asynchronously loaded through a TreeStore and AjaxProxy.js代码如下:
Ext.require([ 'Ext.tree.*', 'Ext.data.*', 'Ext.tip.*']);Ext.onReady(function() { Ext.QuickTips.init(); var store = Ext.create('Ext.data.TreeStore', { proxy: { type: 'ajax', url: 'organization!getDirectSubordinates.action' }, root: { text: '根节点', id: '0', expanded: true }, folderSort: true, sorters: [{ property: 'text', direction: 'ASC' }] }); var tree = Ext.create('Ext.tree.Panel', { store: store, rootVisible:false, viewConfig: { plugins: { ptype: 'treeviewdragdrop' } }, renderTo: 'tree-div', height: 300, width: 250, title: 'Files', useArrows: true, dockedItems: [{ xtype: 'toolbar', items: [{ text: 'Expand All', handler: function(){ tree.expandAll(); } }, { text: 'Collapse All', handler: function(){ tree.collapseAll(); } }] }] });});
java代码如下:
package com.dahuatech.work.action;@Namespace("/")@Scope("prototype")@Controller(value = "organization")public class OrganizationAction extends BaseAction { private String node; @Action(value = "getDirectSubordinates") public String getDirectSubordinates() throws Exception { JSONArray json = new JSONArray(); if (node.equals("0")) { JSONObject object = new JSONObject(); object.put("id", "1"); object.put("text", "广东"); object.put("cls", "folder"); json.add(object); } if (node.equals("1")) { JSONObject ob1 = new JSONObject(); ob1.put("id", "2"); ob1.put("text", "11RPU"); ob1.put("cls", "folder"); json.add(ob1); } if (node.equals("2")) { JSONObject ob1 = new JSONObject(); ob1.put("id", "3"); ob1.put("text", "11Chanel"); ob1.put("leaf", true); ob1.put("cls", "file"); JSONObject ob2 = new JSONObject(); ob2.put("id", "4"); ob2.put("text", "22Chanel"); ob2.put("leaf", true); ob2.put("cls", "file"); json.add(ob1); json.add(ob2); } ActionContext ctx = ActionContext.getContext(); HttpServletResponse response = (HttpServletResponse) ctx .get(ServletActionContext.HTTP_RESPONSE); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.print(json.toString()); return null; } public String getNode() { return node; } public void setNode(String node) { this.node = node; }}
作用:生成异步请求时的json数据。
当展开节点时,前台会把json数据中节点的id通过node参数传送到后台。
0 0
- extjs4 异步树的写法
- extjs4 异步树的写法
- Extjs4 异步复选框树
- Extjs4 异步刷新书的情况下 保持树的展开状态
- 常用的三种异步写法
- Generator 异步操作的同步化写法
- 服务器与客户端异步---》的写法
- 改善异步调用代码的写法
- Extjs4---treepanel+struts2异步加载
- Extjs4 treePanel异步加载菜单
- extjs4.2一种导致内存泄露的代码写法及解决方案
- extjs4.2一种导致内存泄露的代码写法及解决方案
- ExtJS4 树
- Extjs4---treepanel+struts2异步加载,用的accordion布局,MVC做的
- java做微信支付notify_url异步通知服务端的写法
- jquery 异步回调的写法 / deferred对象详解
- js 中&.get、&.post 的同步异步写法
- ExtJS4.1 树的单个节点刷新
- IOS练习题
- sudo.c
- 怎样防止sql注入
- 初识 Cloudera Impala
- Linux中,PHP以root身份运行外部命令-sudo实施方法
- extjs4 异步树的写法
- package,import,include的联系与区别【好】
- Eclipse中SVN的安装步骤(两种)和使用方法
- 最长公共子序列
- eclipse使用技巧一
- 从5个人中选取2个人作为礼仪
- 广语言的一些概念
- tinyXML 中文手册
- 避免使用vector<bool>