Easyui-combotree下拉框组合树

例一:agentTree函数内的id为当前点击的子节点的值(id),没有点击为null

<input name="parent_id" id="parent_id" class="easyui-combotree" data-options="width:200,height:30,url:'agentTree',required:false,
value:'${params.parent_id==null?-1:params.parent_id}',queryParams:{selected:'${params.parent_id==null?-1:params.parent_id}'}">
----------------------------------------------------------------------------------------------------------
/**
	 * 获取代理商树数据
	 * selected 表示树有默认选中的值,修改时返显数据
	 * id 表示点击节点时,展开该节点下级树
	 * @throws Exception  */	 
	@RequestMapping(value="/agentTree")
	public @ResponseBody List<Map<String, Object>> agentTree(String id, String selected){
		List<Map<String, Object>> agentTree = new ArrayList<>();
		
		agentTree=agentService.agentInfoTree();
		return agentTree;
	}

----------------------------------------------------------------------------------------------------------
public List<Map<String, Object>> agentInfoTree(){
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		Map<String, Object> treeHeadMap = new HashMap<String, Object>();
		treeHeadMap.put("id", "-1");//上传的数据
		treeHeadMap.put("text", "请选择");//展示的数据
		result.add(treeHeadMap);
		
		String sql = "select ai.id,ai.agent_name from agent_info ai ";

		List<Map<String, Object>> list =  dao.find(sql);
		for(Map<String, Object> user : list){
			String id = user.get("id").toString();
			String agent_name = user.get("agent_name").toString();
			Map<String, Object> option = new HashMap<String, Object>();
			option.put("id", id);//上传的数据
			option.put("text", id+"/"+agent_name);//展示的数据
			result.add(option);
		}
		return result;
	}		


例二:(1)没有选择子节点,id为null,点击节点,merchantTree函数的id为A+list.get("id")

(2).put("state", "closed");     的意思是将列表转化为文件夹格式,有可选的下拉框

(3)multiple:true, 在节点后增加一个选择框(多选)

<td>商户:</td>
<td>
<input type="hidden" name="merchant_nos" id="merchant_nos"/>
<input name="merchant_no" id="merchant_no_combotree" class="easyui-combotree" 
data-options="lines:true,multiple:true,width:200,height:30,url:'${ctx}/mer/merchantTree',required:false,
value:'${params.merchant_no==null?-1:params.merchant_no}',queryParams:{selected:'${params.merchant_no==null?-1:params.merchant_no}'}">
</td>

@RequestMapping(value="/merchantTree")
				public @ResponseBody List<Map<String, Object>> merchantTree(String id, String selected){
					List<Map<String, Object>> merchantTree = new ArrayList<>();
					merchantTree=merchantService.merchantInfoTree( id, selected);
					return merchantTree;
				}


	public List<Map<String, Object>> merchantInfoTree(String id, String selected) {
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		if(id==null){
			Map<String, Object> treeHeadMap = new HashMap<String, Object>();
			treeHeadMap.put("id", "-1");// 上传的数据
			treeHeadMap.put("text", "请选择");// 展示的数据
			result.add(treeHeadMap);
			String sql="select * from agent_info ai where ai.agent_status='1'";
			List<Map<String, Object>> agentList=dao.find(sql);
			for(Map<String, Object> list:agentList){
				Map<String, Object> option = new HashMap<String, Object>();
				option.put("id", "A"+list.get("id"));// 上传的数据
				option.put("text", list.get("agent_name"));// 展示的数据
				option.put("state", "closed");
				result.add(option);
			}
		}else {
			String sql = "select mi.merchant_name,mi.merchant_no from merchant_info mi where mi.agent_id=?";
			List<Map<String, Object>> list = dao.find(sql,new Object[]{id.substring(1, id.length())});
			for (Map<String, Object> user : list) {
				Map<String, Object> option = new HashMap<String, Object>();
				String merchant_no = user.get("merchant_no").toString();
				String merchant_name = user.get("merchant_name").toString();
				/*Map<String, Object> option = new HashMap<String, Object>();*/
				option.put("id", merchant_no);// 上传的数据
				option.put("text", merchant_no + "/" + merchant_name);// 展示的数据
				result.add(option);
			}
		}
		return result;
	}


附上JS

$(function () {
	$("#transChartQuery").click();
});

/**
 * combotree事件
 */
function saleIdComboTree(){
	var saleIds = $("#sale_id_combotree").combotree("getValues");
	$("#sale_ids").val(saleIds);
	var agent_nos = $("#agent_no_combotree").combotree("getValues");
	$("#agent_nos").val(agent_nos);
	var merchant_nos = $("#merchant_no_combotree").combotree("getValues");
	$("#merchant_nos").val(merchant_nos);
}

/**
 * 点击查询按钮
 */
function submitQuery(){
	saleIdComboTree();
	var params = $("form").serialize();
	var lineChartData = getData(params, "/transchart/query");
	creatLineChart(lineChartData); // 线型图
}


function creatLineChart(data){
	$('#lineChart').highcharts(data);
}


function getData(params, url){
	var result = "";
	$.ajax({
		cache: true,
        type: "POST",
        data: params,
        async: false,
        error: function(request) {
            $.messager.alert("提示", "系统错误!", "success");
        },
        url: ctx() + url,
        dataType: "json",
        success: function(data) {
        	if(data.errCode=="1"){
        		$.messager.alert("提示", data.msg, "error");
        		return;
        	}else{
        		result = data;
        	}
        	
        }
     });
	return result;
}



后台对数据的处理

String[] arr = params.get("merchant_nos").toString().split(",");
			arr = (String[]) ArrayUtils.removeElement(arr, "-1");

List<String> list = Arrays.asList(arr);


for(int i=0; i<list.size(); i++){
			String id = list.get(i);
			if(id.startsWith("A")){
				id = id.substring(1, id.length());
....
}else{
				result.add(id);
			}
		}






猜你喜欢

转载自blog.csdn.net/q975583865/article/details/73647866