这里是js类 创建一个树。。
从java 类中 直接返回一个 bean 的集合(List ,Set)都行。。。
Ext.BLANK_IMAGE_URL='js/resources/images/vista/s.gif';
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
Ext.onReady(function()...{
vari=20;
//从DWR中加载数据自动转换成json格式
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
vartreeLoader=newExt.tree.DWRTreeLoader(...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dwrCall:CheckBean.getTreeNode//调用java方法
});
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//定义树
varTree=Ext.tree;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
vartree=newTree.TreePanel(...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
el:'tree-div',//目标div容器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
animate:true,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
enableDD:true,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
containerScroll:true,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
loader:treeLoader
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
});
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//树中加入一个右键菜单事件
tree.on('contextmenu',onContextMenu);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
functiononContextMenu(node,e)...{
varmenu;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(!menu)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
menu=newExt.menu.Menu([...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
id:node.id+'add',
text:'添加一个文件',
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
handler:function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
node.appendChild(newTree.AsyncTreeNode(...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
text:node.childNodes.length.toString(),
id:i+++'',
expanded:true
}));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
},...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
id:node.id+'del',
text:'删除接点',
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
handler:function()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(node.id!=-1)...{
node.remove();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Ext.Msg.alert('错误','根结点不能删除');
}
}
}]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
menu.showAt(e.getPoint());
node.on('append',onAppend);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
functiononAppend(tree,thisNode,newNode,index)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
alert();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//定义根节点
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
varroot=newExt.tree.AsyncTreeNode(...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
text:'组织机构图',
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
draggable:false,
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
id:'-1'//默认的node值:?node=-1
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
});
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
tree.setRootNode(root);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
tree.render();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
root.expand();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
});
bean 的命名 必须 遵守规范
所有字段 必须遵守命名规范
如何不想使用这样的命名 就要修改 Ext.tree.DWRTreeloader.js这个类
packagecom;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
importjava.util.List;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
publicclassOrgBean...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//是否加载字节点下的所有节点
privatebooleanchildrenLoaded=false;
//是否用子节点
privatebooleanhasChildren=true;
//是否加载时候展开
privatebooleanexpanded=false;
//tree的id属性
privateStringid;
//tree的name属性
privateStringtext;
//当前类的集合
privateList<OrgBean>children;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicList<OrgBean>getChildren()...{
returnchildren;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicvoidsetChildren(List<OrgBean>children)...{
this.children=children;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicStringgetId()...{
returnid;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicvoidsetId(Stringid)...{
this.id=id;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicStringgetText()...{
returntext;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicvoidsetText(Stringtext)...{
this.text=text;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicbooleanisChildrenLoaded()...{
returnchildrenLoaded;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicvoidsetChildrenLoaded(booleanchildrenLoaded)...{
this.childrenLoaded=childrenLoaded;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicbooleanisExpanded()...{
returnexpanded;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicvoidsetExpanded(booleanexpanded)...{
this.expanded=expanded;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicbooleanisHasChildren()...{
returnhasChildren;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicvoidsetHasChildren(booleanhasChildren)...{
this.hasChildren=hasChildren;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
OrgDwr.java
没什么好说的 一个 递归 加载数据
packagecom;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
importjava.util.List;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
publicclassOrgDwr...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
privateOrgDAOorgDAO=newOrgDAO();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
publicList<OrgBean>getTreeNode(StringtreeId)...{
System.out.println(treeId);
List<OrgBean>list=orgDAO.findByParentID(Integer.parseInt(treeId));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
returnget(list);
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
privateList<OrgBean>get(List<OrgBean>list)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
for(OrgBeanbean:list)...{
System.out.println(bean.getText());
List<OrgBean>list2=orgDAO.findByParentID(Integer.parseInt(bean.getId()));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(list2.size()>0)...{
bean.setChildren(list2);
get(list2);
break;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
bean.setHasChildren(false);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
returnlist;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
html 如何 引用 超级简单 把几个 js 加载进去就ok了
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<%...@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<%...
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"://"
+request.getServerName()+":"+request.getServerPort()
+path+"/";
%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html>
<head>
<basehref="<%=basePath%>">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<title>MyJSP'org.jsp'startingpage</title>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<linkrel="stylesheet"type="text/css"
href="js/resources/css/ext-all.css"/>
<scripttype="text/javascript"src="js/ext-base.js"></script>
<scripttype="text/javascript"src="js/ext-all.js"></script>
<scripttype="text/javascript"src="js/MyAsynTreeNode.js"></script>
<scripttype="text/javascript"src="js/DWRTreeLoder.js"></script>
<scripttype='text/javascript'
src='/ExtTree/dwr/interface/CheckBean.js'></script>
<scripttype='text/javascript'src='/ExtTree/dwr/engine.js'></script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<scripttype='text/javascript'src='/ExtTree/dwr/util.js'></script>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<scripttype="text/javascript"src="js/extdwr.js"></script>
</head>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
<!--树加载的位置-->
<divid="tree-div"
style="overflow:auto;height:300px;width:200px;border:2pxsolid#c3daf9;"></div>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
</html>
用需要 源码的话 把邮箱留下来 我给你们传过去
分享到:
相关推荐
用的东西比较杂,主要为了学习一下知识呵呵: ssh2、dwr、jquery、extjs、jquery weekcalendar、jfreechart、jasperreport 联系人实现了拖动实现好友分组。可以把grid直接拖到tree,不同于其他的例子,拖动grid后会...
Extjs Tree + JSON + Struts2 示例源代码
13.7 Ext.ux.DWR 13.7.1 Ext.data.DwrProxy 13.7.2 Ext.data.DWRTreeLoader 13.7.4 Web服务端配置 13.7.5 服务层接口 第14章 ExtJS扩展 14.1 利用Ext.extend实现继承 14.2 与ExtJS扩展相关的预备知识 14.2.1...
用的东西比较杂,主要为了学习一下知识呵呵: ssh2、dwr、jquery、extjs、jquery weekcalendar、jfreechart、jasperreport 联系人实现了拖动实现好友分组。可以把grid直接拖到tree,不同于其他的例子,拖动grid后会在...
13.7 Ext.ux.DWR 13.7.1 Ext.data.DwrProxy 13.7.2 Ext.data.DWRTreeLoader 13.7.4 Web服务端配置 13.7.5 服务层接口 第14章 ExtJS扩展 14.1 利用Ext.extend实现继承 14.2 与ExtJS扩展相关的预备知识 14.2.1...
用的东西比较杂,主要为了学习一下知识呵呵: ssh2、dwr、jquery、extjs、jquery weekcalendar、jfreechart、jasperreport 联系人实现了拖动实现好友分组。可以把grid直接拖到tree,不同于其他的例子,拖动grid后会在...
2.7.3. 迫不得已,要加上后台脚本了。 2.7.4. 其实分页不一定要踩在脚下,也可以顶在头上。 2.7.5. 谣言说ext不支持前台排序 2.8. 爱生活,EditorGrid。 2.8.1. 旋动舞步,看我们怎么把这个EditorGrid炫出来。 2.8.2...
9.2. 带全选的checkbox树形CheckBoxTree 9.3. 带全选的checkbox的grid 9.4. fisheye 9.5. 可以设置时间的日期控件 9.6. JsonView实现用户卡片拖拽与右键菜单 9.7. 下拉列表选择每页显示多少数据 10. 撕裂吧!...
9.2. 带全选的checkbox树形CheckBoxTree 9.3. 带全选的checkbox的grid 9.4. fisheye 9.5. 可以设置时间的日期控件 9.6. JsonView实现用户卡片拖拽与右键菜单 9.7. 下拉列表选择每页显示多少数据 10. 撕裂吧!...
再加上设计轻巧的JQuery框架,一个完美的整合框架由此而生。 3.真实的案例 该案例是一个价值6万元的项目,当然在功能和工作量上有部分缩水,但是技术绝对不会缩水。 4.项目中技术点: 该项目中的技术点可谓众多,每个...