Java后台返回easyUI的comboxTree数据

easyUI的实现,其中包括一次加载完毕和动态树:

 

public void getAllOrgTree() throws IOException
    {
        log.info("getAllOrgTree start");
        Integer parentId = Integer.valueOf(0);
        if (StringUtils.isNotEmpty(node))
        {
            parentId = Integer.valueOf(node);
        }
        List optionList = new ArrayList();

        this.getAllOrgTree(optionList, parentId);
        JSONArray jsonArray = JSONArray.fromObject(optionList);
        super.response.getWriter().write(jsonArray.toString());

    }

    @SuppressWarnings("unchecked")
    private void getAllOrgTree(List treeList, Integer orgId)
    {
        BusinessResponse businessResponse = orgService.getAllOrgByParentId(orgId);
        List orgList = (List) businessResponse.getAttribute(CommonConstant.RESULT);

        for (Org org : orgList)
        {
            IvOrgTreeVo treeVo = new IvOrgTreeVo();
            treeVo.setId(org.getSysId());
            treeVo.setText(org.getOrgName());

            BusinessResponse countResponse = orgService.getOrgCountByParentId(org.getSysId());
            Long total = (Long) countResponse.getAttribute(CommonConstant.TOTAL_COUNT);
            if (total > 0)
            {
                List optionList = new ArrayList();
                getAllOrgTree(optionList, org.getSysId());
                treeVo.setChildren(optionList);
                treeVo.setState("closed");
                treeList.add(treeVo);
            }
            else
            {
                treeList.add(treeVo);
            }
        }
    }

//动态树的方法
 public void getEasyUITree() throws IOException
    {
        Integer parentId = Integer.valueOf(0);
        if (StringUtils.isNotEmpty(node))
        {
            parentId = Integer.valueOf(node);
        }
        
        BusinessResponse businessResponse = orgService.getAllOrgByParentId(parentId);
        List orgList = (List) businessResponse.getAttribute(CommonConstant.RESULT);
        List optionList = new ArrayList();
        for (Org org : orgList)
        {
            IvOrgTreeVo treeVo = new IvOrgTreeVo();
            treeVo.setId(org.getSysId());
            treeVo.setText(org.getOrgName());
            
            BusinessResponse countResponse = orgService.getOrgCountByParentId(org.getSysId());
            Long total = (Long) countResponse.getAttribute(CommonConstant.TOTAL_COUNT);
            if (total > 0)
            {
                treeVo.setState("closed");
            }
            else
            {
                treeVo.setState("open");
            }
            
            optionList.add(treeVo);
        }
        JSONArray jsonArray = JSONArray.fromObject(optionList);
        super.response.getWriter().write(jsonArray.toString());
        
    }

 

 

JSP页面展示:

 




jQuery EasyUI
	
	
	
	
	


	

ComboTree

Select:

 

 


Java后台返回easyUI的comboxTree数据_第1张图片
 附:easyUI的API地址,http://www.jeasyui.com/documentation/index.php

你可能感兴趣的:(Java综合知识)