当前位置: 代码迷 >> Web前端 >> easyui-tree.动态铺展节点
  详细解决方案

easyui-tree.动态铺展节点

热度:827   发布时间:2012-12-19 14:13:14.0
easyui-tree.动态展开节点
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <base href="<%=basePath%>">  
	<title></title>
	<link rel="stylesheet" type="text/css" href="<%=basePath%>easyui/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="<%=basePath%>easyui/themes/icon.css"/>
	<script type="text/javascript" src="<%=basePath%>easyui/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	$(function(){	
		 //动态获取tree,行政区列表
		 $('#xianTree').tree({
				checkbox : true,
				onlyLeafCheck:true,
				url : "xmlx/projectSelectionAction!getDeptTrees.action?departid=2939",
				onBeforeExpand : function(node, param) {
					$('#xianTree').tree('options').url = "xmlx/projectSelectionAction!getDeptTrees.action?departid="+node.id;// change the url  
				},
				onCheck:function(data, checked) {
					
				}
		 });
		 
		//给页面所有年份赋值
			var myDate = new Date(); //js得到当前日期
			var endyear=myDate.getFullYear();  //得到当前年
			for(var i=endyear;i>=2009;i--){  
				 $("#year").append('<option value="'+i+'">'+i+'年</option>');  //查询年份赋值 						 
			} 
		 //遍历选中的行政区
		 $("#setMsg").click(function(){
			 var year=$("#year").val();
			 var entytype=$("input[name='entytype']:checked").val();
			 var nodes = $('#xianTree').tree('getChecked');
			 var msgJson="[";
             for (var i = 0; i < nodes.length; i++) {
                 msgJson+="{";
                 msgJson+="districtcode:"+nodes[i].attributes.districtcode+",";
                 msgJson+="year:"+year+",";
                 msgJson+="entytype:"+entytype+"";
                 msgJson+="}";
                 
                 if(i+1>=nodes.length){
                	 msgJson+="";
                 }else{
                	 msgJson+=",";
                 }
             }
			 msgJson+="]";
			 
			 $.ajax({
				 type:"post",
				 url:"jbxxlr/countyrecordTypeAction!addCountyRecordTypes.action",
				 data:{jsonstr:msgJson},
				 success:function(msg){
					 $.messager.alert("系统提示","保存成功");
				 },
				 error:function(){
					 $.messager.alert("系统提示","保存成功");
				 }
			 });
		 });
		 
		
	});
</script>


</head>

<body class="easyui-layout" >
	<div region="west" style="width:200px;">
		<ul id="xianTree"></ul>
	</div>
	<div region="center" class="easyui-layout">
			<div region="center" style="text-align:center;">
				年份:<select id="year">
				</select><br />
				填报类型:<input type="radio" value="2" name="entytype"/>县
				<input type="radio" value="1" name="entytype" />镇
				<input type="radio" value="0" name="entytype" />村
			</div>
			<div region="south" style="height:30px; line-height:30px; text-align:right;" border="false">
				 <a class="easyui-linkbutton" id="setMsg" iconCls="icon-ok">确定</a> 
				 <a class="easyui-linkbutton" id="cancel" iconCls="icon-cancel">取消</a> 
			</div>
	</div>
</body>
</html>
当然这是需要后天给予返回有效的json数据的。


  相关解决方案