问题描述
数据库字段:id parentID name可以帮我用extjs struts2 json tree 写一颗树出来吗要求具体点:这是我写的extjsvar root = new Ext.tree.AsyncTreeNode({ id:'-1', text:"XXX公司", loader:new Ext.tree.TreeLoader({ url:"getAar.action", listeners:{ "beforeload":function(treeloader,node) { treeloader.baseParams={ id:node.id, method:'POST' }; } } })});var tree =new Ext.tree.TreePanel({ title:"动态Tree", width:350, height:300, root:root, autoScroll:true,//显示滚动条 animate : true,//true表示使用动画展开/折叠 listeners:{'click':function(node){alert(node.id);//得到的节点 } }});tree.getRootNode().expand(true);我到action: aarList=areaService.getAar(); return Action.SUCCESS;另外我拿到的aarList以这样的数据库结构怎么变成List<Map> 才能得到我想要的接送格式啊 求求各位大哥们帮小弟想想啊 我快疯了
解决方案
/** * 得到地区树下拉框(异步加载) * @throws IOException */public void getAreeTree() throws IOException {Hashtable areahash = new Hashtable(); Area area = new Area(); Area parentArea = new Area();List areaList = null;ArrayList treeNodeArray = new ArrayList();String parentid = this.getRequest().getParameter("parentid"); //地区父地区if (parentid!=null && !"".equals(parentid)) {//如果父地区不为空parentArea.setAreaId(parentid);area.setParentArea(parentArea);areaList = areaManager.getSubAreaList(parentArea);}else {//如果父地区为空area.setParentArea(parentArea);areaList = areaManager.getAreaList(area);}//for (int i = 0; areaList != null && i < areaList.size(); i++) {//area = (Area)areaList.get(i);//areahash.put(area.getAreaId(), area.getAreaName());//}for (int i = 0; areaList != null && i < areaList.size(); i++) {area = (Area)areaList.get(i);JSONTreeNode TreeNode = new JSONTreeNode();TreeNode.setArr("?parentid="+area.getParentArea().getAreaId()); TreeNode.setId(area.getAreaId()); TreeNode.setText(area.getAreaName());//if(areahash.containsKey(area.getAreaId())){//TreeNode.setChecked(true);//}else{//TreeNode.setChecked(false);//}List sublist = null;sublist =areaManager.getSubAreaList(area);if (sublist.size() > 0) {//如果该地区有子地区,则该地区不为子节点TreeNode.setLeaf(false);TreeNode.setIconCls("icon-treeg");TreeNode.setSingleClickExpand(true);} else {TreeNode.setLeaf(true);TreeNode.setIconCls("icon-treep");}//TreeNode.setExpandable(false);treeNodeArray.add(TreeNode);}outJson(treeNodeArray);}
解决方案二:
我blog里有。自己看吧。