jquery easyui combotree 树实例简单应用

在使用jquery easyui之前 要先引入js:


		
		

定义一个input 作为树显示表单,并初始化,调用action:


										

action请求,编写树结构,返回json数据:

public void combotree() throws IOException{
		List list=new ArrayList();
		
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setCharacterEncoding("UTF-8");
		
		List organizationList=wfs.getOrganizationList();
		
		for(Organization orz : organizationList){
			 ComboTreeModel ctm = new ComboTreeModel();
             ctm.setId(orz.getOrgName());
             ctm.setText(orz.getOrgName());
             
             List children = new ArrayList();
             for(Organization organization : organizationList){
            	 if(orz.getOrgName().equals(organization.getOrgName())){
            	ComboTreeModel comboTreeModel = new ComboTreeModel();
                   comboTreeModel.setId(organization.getAdminName());
                   comboTreeModel.setText(organization.getAdminName());
                   children.add(comboTreeModel);
            	 }
             }
             ctm.setChildren(children);
             list.add(ctm);
		}
        String json = JSONArray.fromObject(list).toString();
        response.getWriter().print(json);
		
	} 

如果需要只选中子节点,选中父节点清除:

$(function(){
											$("#tree").combotree({
													url:'combotree.action',
													onSelect:function(node){
														var tree = $(this).tree; //返回树对象
														
														// 选中的节点是否为叶子节点,如果不是叶子节点,清除选中
														var isLeaf = tree('isLeaf', node.target);
														if(!isLeaf){
															$("#tree").combotree('clear');  //清除选中
														} 
													}
												});
											});


你可能感兴趣的:(jquery,jquery,easy,ui,combotree,树结构)