本文共 9480 字,大约阅读时间需要 31 分钟。
empListTree = new Ext.tree.TreePanel({
id : 'tree1', region : 'west', useArrows : true, autoScroll : true, autoHeight : false, animate : true, border : true, width : 190, margins : '5 0 5 5', cmargins : '0 0 0 0', enableDD : false, collapseMode : 'mini', dataUrl : baseUrl+'/pef/mytargetsAction.do?method=getTreeVo', tbar : cempListTbar, lines : false, root : { nodeType : 'async', text : '未提交的绩效合同', id : 'xxx', iconCls : 'unit-com', draggable : false }, listeners : { 'click' : function(node){ pefFormulaGridStore.removeAll(); childGridStore.removeAll(); Ext.DomHelper.overwrite(document.getElementById("pefFormulaTopDiv"), " "); var _type = node.id.split('-')[0]; if(_type == '5'){ var pcId = node.id.split('-')[1];//isSuperior _isSuperior = node.id.split('-')[2]; go_to(pcId); currentId = pcId; pcId = pcId; _currentId = pcId; getPcState(pcId); getTitle(pcId); clickTreeBtnControl(_isSuperior); }else{ pefFormulaGrid.addPefFormulaBtn.setDisabled(true); pefFormulaGrid.wizardBtn.setDisabled(true); pefFormulaGrid.copyPefFormulaBtn.setDisabled(true); pefFormulaGrid.viewProgressChart.setDisabled(true); } if(_isSuperior == '3'){// 上级 pefFormulaGrid.subPefFormulaBtn.setDisabled(true); clickTreeBtnControl(_isSuperior); } return true; } } }); userId = new Ext.form.Hidden({ hidden : true, name : 'userId', renderTo : 'userId' }); userName = new Ext.form.Hidden({ hidden : true, name : 'userName', renderTo : 'userName' }); empListTree.getRootNode().expand();//加载数据展开树 empListTree.on('beforeload', function(node) { empListTree.loader.dataUrl = baseUrl+'/pef/mytargetsAction.do?method=getTreeVo&pcState='+pcState; }); //重新加载树节点 function reloadTree(){ var node = empListTree.getNodeById(currentId); if(node.isLeaf()){//如果是子节点重新加载上级,再加载当前节点 empListTree.getNodeById(node.parentNode.id).reload({params : {ebId : node.id}}); }else{//不是子节点重新加载当前节点 node.reload({params : {ebId : node.id}}); } }
/**********************************************************************************/
/**
* 列出左边树的结构 * @author sunlei * @param actionMapping * @param actionForm * @param request * @param response * @return * @throws Exception */ public ActionForward getPefFormulaTree(ActionMapping actionMapping,ActionForm actionForm, HttpServletRequest request, HttpServletResponse response)throws Exception{ LoginInfo loginInfo = (LoginInfo) request.getSession().getAttribute(Global.LOGIN_INFO); MytargetsService mytargetsService = (MytargetsService)SpringHelper.getBean("MytargetsService"); EmpBasicinfoService empBasicinfoService = (EmpBasicinfoService)SpringHelper.getBean("EmpBasicinfoService"); List treeList = new ArrayList(); List<HashMap> pfList = new ArrayList(); String nodeId = request.getParameter("node"); String state = request.getParameter("state"); if(null == state || "".equals(state) || "null".equals(state) || "undefined".equals(state)){ state = "0"; } if(null == nodeId || "".equals(nodeId) || "null".equals(nodeId)){ nodeId = "0"; } if("0".equals(nodeId)){ pfList = mytargetsService.getPefFormulaByEbIdReturnChildList(loginInfo.getUserId(),state); for(int i = 0; i < pfList.size(); i++){ HashMap pfMap = pfList.get(i); TreeVO treePefVo = new TreeVO(); treePefVo.setId("" + pfMap.get("PF_ID")); treePefVo.setText("" + pfMap.get("PF_NAME")); treePefVo.setLeaf(false); treePefVo.setIconCls("fangan"); treePefVo.setSingleClickExpand(true);// EmpBasicinfoPO empBasicinfo = empBasicinfoService.findByIdEmpBasicinfoPO(Long.valueOf(loginInfo.getUserId()));// Long ebSex = empBasicinfo.getEbSex();// if(ebSex == 1){ // treePefVo.setIconCls("male");// } else if(ebSex == 2){ // treePefVo.setIconCls("female");// } else { // treePefVo.setIconCls("user");// } treeList.add(treePefVo); } }else if("0-".equals(nodeId.substring(0, 2))){ List<HashMap> empList = mytargetsService.getEmpByPefFormulaIdReturnChildList(nodeId.split("-")[1], state,loginInfo.getUserId());//treePefVo.getId().substring(treePefVo.getId().indexOf("-")+1)); for(int j = 0; j < empList.size(); j++){ HashMap empMap = empList.get(j); TreeVO treeEmpVo = new TreeVO(); treeEmpVo.setId("" + empMap.get("PC_ID")); treeEmpVo.setText("" + empMap.get("EB_NAME")); treeEmpVo.setLeaf(true); treeEmpVo.setSingleClickExpand(true); //treeEmpVo.setIconCls("fangan"); EmpBasicinfoPO empBasicinfo = empBasicinfoService.findByIdEmpBasicinfoPO(Long.valueOf(empMap.get("EB_ID").toString().substring(2))); Long ebSex = empBasicinfo.getEbSex(); if(ebSex == 1){ treeEmpVo.setIconCls("male"); } else if(ebSex == 2){ treeEmpVo.setIconCls("female"); } else { treeEmpVo.setIconCls("user"); } treeList.add(treeEmpVo); } } //格式化为JSONArray JSONArray jsonTree = JSONArray.fromObject(treeList); //输出 response.getWriter().print(jsonTree.toString()); log.debug(jsonTree.toString()); return null; }/**********************************************************bs****************************
var tree=new Ext.tree.TreePanel({
applyTo:id, // id:"organizationTree", id:'organizationManage_leftPanel', checked:true, lines:false, width:250, checkModel: 'cascade', onlyLeafCheckable: false, animate: true, border:false, rootVisible: false, //******** autoScroll:true, trackMouseOver:true, loader: new Ext.tree.TreeLoader({ dataUrl:fdLocalUrl+'/organizationChildren.bs', baseAttrs: { uiProvider: Ext.tree.TreeCheckNodeUI } }), listeners: { 'click': function(node, event){ // var metaDiv=document.getElementById("organizationManage_");// var parent=metaDiv.parentNode;// parent.removeChild(metaDiv);// var newDiv=document.createElement("div");// newDiv.setAttribute("id", "organizationManage_");// //newDiv.setAttribute("class", "mainbody");// parent.appendChild(newDiv); removeDiv("organizationManage_"); getOrganizationlInit("organizationManage_",node.id); } }, root: new Ext.tree.AsyncTreeNode({ id:rootid, text:roottext, listeners:{//监听 "click":function(node,e){ node.reload(); } } }) });
public String getRootTreeByJson(){
// System.out.println("getRootTreeByJson"); Bs bs = BsFactory.getBs(); SystemManager sm=bs.getSystemManager(); try{ ExtTreeModel em=sm.getOrganizationTree(); this.setRootId(em.getId()); this.setRootText(em.getText()); this.success=true; return SUCCESS; }catch(Exception e){ e.printStackTrace(); } return SUCCESS; } public String treeOrganization(){ //System.out.println("treeOrganization"); HttpServletRequest request=ServletActionContext.getRequest(); Bs bs=BsFactory.getBs(); SystemManager sm = bs.getSystemManager(); try{ ExtTreeModel em=sm.getOrganizationTree(); JSONArray arr = new JSONArray(); this.setJsonTree( arr.fromObject(em.getChildren()).toString()); request.setAttribute("jsonTree", this.getJsonTree()); return SUCCESS; }catch(Exception e){ e.printStackTrace(); } return SUCCESS; }
import java.util.ArrayList;
import java.util.List;
/**
* @author Dragon.zhao * */public class ExtTreeModel { private String id = null; private String text = null; private boolean leaf = false; //private Set children = new HashSet(); private List children = new ArrayList(); //customer attributes private String linkUrl =null; private int splitNum; private String dataType; private String description; private String specialAttr; /** * @return the id */ public String getId() { return id; } /** * @param id the id to set */ public void setId(String id) { this.id = id; } /** * @return the text */ public String getText() { return text; } /** * @param text the text to set */ public void setText(String text) { this.text = text; } /** * @param splitNum the splitNum to set */ public void setSplitNum(int splitNum) { this.splitNum = splitNum; } /** * @return the splitNum */ public int getSplitNum() { return splitNum; } /** * @return the leaf */ public boolean isLeaf() { return leaf; } /** * @param leaf the leaf to set */ public void setLeaf(boolean leaf) { this.leaf = leaf;// if(leaf){ // this.children=null;// } } /** * @param linkUrl the linkUrl to set */ public void setLinkUrl(String linkUrl) { this.linkUrl = linkUrl; } public List getChildren() { return children; } public void setChildren(List children) { this.children = children; } /** * @return the linkUrl */ public String getLinkUrl() { return linkUrl; } public String getDataType() { return dataType; } public void setDataType(String dataType) { this.dataType = dataType; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getSpecialAttr() { return specialAttr; } public void setSpecialAttr(String specialAttr) { this.specialAttr = specialAttr; } }
public ExtTreeModel getOrganizationTree() throws BsException {
ExtTreeModel em = new ExtTreeModel(); List list = getOrganizations("%"); Iterator ita = (Iterator) list.iterator();while (ita.hasNext()) {
Organization org = (Organization) ita.next(); if (org.getParent() == null) { em.setId(org.getId()); // System.out.println("org.getOrgId"+org.getId()); em.setLeaf(false); em.setText(org.getOrgName()); OrganizationTreeBuilder(em, list); } } return em; }private void OrganizationTreeBuilder(ExtTreeModel em, List list) {
Iterator ita = list.iterator(); //System.out.println("OrganizationTreeBuilder 中 list.size=="+list.size() // ); while (ita.hasNext()) { Organization org = (Organization) ita.next(); // System.out.println("生成的org=="+org.toString()); if (org.getParent() != null) { if (em.getId().equals(org.getParent().getId())) { ExtTreeModel etm = new ExtTreeModel(); etm.setId(org.getId()); etm.setText(org.getOrgName()); etm.setLeaf(false); em.getChildren().add(etm); OrganizationTreeBuilder(etm, list); } } } }转载地址:http://mzlvi.baihongyu.com/