ExtJS Tree刷新后自动展开并选择节点
实例讲解:通过点击岗位,将岗位对应的模块菜单给展开。
1.点击岗位获取对应模块菜单ID:
function check(node,checked){ if(checked == true){ //得到岗位对应的功能 Ext.Ajax.request({ url : 'user.up?doType=getModuleById', params : {postID : node.id}, success : function(response, options) { checkModuleid = response.responseText; module_root.reload();//这是个根节点,此处不用treeLoader.reload() } }); } }
结果示例:{03,0302,0305,05,0504}
2.通过获取到的ID获取对应的Path路径:
moduleloader.on("load",function(treeLoader, node){ var ids = checkModuleid?checkModuleid.split(","):null; if(!ids){//||ids.length==0 return; } for(var i = 0;i<ids.length;i++){ Ext.Ajax.request({ url: "user.up?doType=moduleExpandTo", params: { id:ids[i]}, success:function(response,option){ var result = Ext.util.JSON.decode(response.responseText); if(result.math=="no")return; module_tree_node.expandPath('module_tree/module_root/' + result.path, 'id', onExpandPathComplete); } }); } });
Servlet:
if("moduleExpandTo".equals(action)){ response.setContentType("text/json;charset=UTF-8"); out=response.getWriter(); String id = request.getParameter("id"); String path = uDao.getPathOfModuleNode(id); if(path ==null||"".equals(path)){ json = "{match:'no'}"; }else{ json = "{match:'yes',path:'"+path+"'}"; } out.print(json); out.close(); return; }
Dao:
public String getPathOfModuleNode(String id) { String path = null; StringBuffer sql = new StringBuffer( "select moduleid,name from modules where enable = 1 connect by prior pid = moduleid start with moduleid='") .append(id); sql.append("' order by LEVEL DESC"); Session s = null; try { s = HibernateUtil.getSession(); s.beginTransaction(); SQLQuery query = s.createSQLQuery(sql.toString()); List lst = query.list(); if (lst != null && lst.size() > 0) { StringBuffer sp = new StringBuffer(""); for (int i = 0; i < lst.size(); i++) { Object[] flds = (Object[]) lst.get(i); sp.append((String) flds[0]); if (i < lst.size() - 1) { sp.append("/"); } } path = sp.toString(); } s.getTransaction().commit(); } catch (Throwable e) { log.error(e.toString()); HibernateUtil.endSession(s); } finally { HibernateUtil.endSession(s); } return path; }
3.展开树的方法:
function onExpandPathComplete(flag, node) { if(!flag) { return; } if(node){ node.ensureVisible();//确保该节点可见——即不可见时将展开其父目录使其可见。 node.select() ; //选中该节点!——即底纹变浅蓝色(相当于对该节点做了单击!!!) //方式二:treePanel.getSelectionModel().select(node); if(node.leaf){ node.ui.toggleCheck(true); //选中复选框 } } }
注意:
1.被选中项显示勾的方式——即复选框勾选的方式:
2.展开树——即展开选中节点的父节点的方式:
2.选中节点——相当于鼠标单击了该节点:
(1).
(2).
图示:
相应例子:http://atian25.iteye.com/blog/724092
相关推荐
区别在于,远程脚本调用方式加载树节点信息使用的是WebInvokeTreeLoader,需要通过fn属性来指定用于加载数据的远程方法,并在beforeload事件处理器设置参数远程方法调用的参数值。而传统的树节点加载器是Ext.tree....
ExtJs Tree
Extjs的tree Extjs的tree Extjs的tree Extjs的tree Extjs的tree
ExtJs 2.2.1 tree实例,内附mysql数据文件 1. 数据节点一次性加载 2. 节点分为两个类(项目和设备) 3. 右键菜单 4. 节点增、删、改操作 ....... 后台是java struts1。 本例旨在说明extjs的tree操作,后台操作很简陋...
最近在学习extjs tree,有两个不错的例子,希望对需要的朋友有所帮助!
完美的Extjs4 treePanel节点刷新,函数为自动刷新选中的节点.API看得头疼才别出来的代码.截止我发之前,好像没有谁共享这个功能的函数吧.
extjs tree 异步加载树型完整的一个web工程,自已已经试过,可用。
extjs tree 学习资料extjs tree 学习资料extjs tree 学习资料extjs tree 学习资料
ExtJs4 Checkbox tree
extjs的tree的使用.doc
Extjs Tree + JSON + Struts2 例子
Extjs Tree + JSON + Struts2 示例源代码
access 数据库,可增加 删除树节点!!
Ext各种组件的使用实例,Extjs tree+grid+form+panel 使用实例
利用extjs框架实现的后台经典显示, tree框架,动态加载。
在网上下载别人的代码,改进加上CHECKBOX ,但是批量删除做不出来,希望高手完成并分享。
Extjs4下拉树菜单 ComboBoxTree 支持单选和多选并且支持展开选中指定节点的通用控件 在项目中已经成熟运用 值得收藏和运用
分享一个ExtJs Tree, 完整的带有复选框的树形结构
TreePanel的各项属性能帮助我们动态加载extjs tree
将文件拷贝到extjs根目录下。运行即可。实现了选中之类。父类联动选中