前台JS
Ext.onReady(function(){
var treeLoader = new Ext.tree.TreeLoader({
dataUrl:'../servlet/basic?action=treePanelTest',
listeners:{
beforeload:function(treeLoader,node){
alert(node.attributes.id);
treeLoader.baseParams.parentID = node.attributes.id;
//将AsyncTreeNode中的id传给变量parentID,然后交个Servlet处理
}
}
});
var form = new Ext.tree.TreePanel({
renderTo:'hello',
root: new Ext.tree.AsyncTreeNode({id:'-1',text : '根节点'}),
rootVisible:true,//判断根节点是否显示
loader:treeLoader
});
});
后台Servlet:
JSONArray array = new JSONArray();
JSONObject json;
if ("-1".equals(req.getParameter("parentID"))) {
List<Company> list = CompanyService.getAllCompanyList();
for (Company company : list) {
json = new JSONObject();
json.accumulate("id", company.getId());
json.accumulate("text", company.getName());
json.accumulate("leaf", false);
array.add(json);
}
} else {
long parentID = Long.parseLong(req.getParameter("parentID"));
Company company = CompanyService.findCompanyByID(parentID);
for (Company dept : company.getDepartments()) {
json = new JSONObject();
json.accumulate("id", dept.getId());
json.accumulate("text", dept.getName());
json.accumulate("leaf", false);
array.add(json);
}
for (User user : company.getStaff()) {
json = new JSONObject();
json.accumulate("id", user.getId());
json.accumulate("text", user.getUserName());
json.accumulate("leaf", true);
array.add(json);
}
}
String retJSON = array.toString();
分享到:
相关推荐
ExtJs4 Checkbox tree
extjs grid 遍历
区别在于,远程脚本调用方式加载树节点信息使用的是WebInvokeTreeLoader,需要通过fn属性来指定用于加载数据的远程方法,并在...而传统的树节点加载器是Ext.tree.TreeLoader,需要指定一个url来获得json数据。
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的使用.doc
Extjs的Tree和Pane配合使用使用json做tree数据交互,感谢csdn,所以我也得做些贡献,获得一些积分
Extjs 4.1 下拉框 Tree 的实现(mvc)
ExtJs Tree
checkbox tree extjs2checkbox tree extjs2checkbox tree extjs2checkbox tree extjs2
Extjs Tree + JSON + Struts2 示例源代码
学习extjs资料,tree合成grid,很不错的视频文件,值得收藏
最近在学习extjs tree,有两个不错的例子,希望对需要的朋友有所帮助!
Ext_Tree 树形菜单
extjs tree 异步加载树型完整的一个web工程,自已已经试过,可用。
extjs tree 学习资料extjs tree 学习资料extjs tree 学习资料extjs tree 学习资料
Extjs动态树的实现以及节点拖拽
获取Extjs中的TreePanel中所有的被checked的叶子节点的id
利用extjs框架实现的后台经典显示, tree框架,动态加载。
通过java 访问数据库而生成节点 子节点的 ID 与 父节点的关系为“父节点id_子节点id”此id为数据库中的id 同理“父节点id_子节点id_子子节点id”,因此加载树时将node.id做为参数 通过split("_"),根据数据的长度就...