json数据 二级联动

zaiqing_shenhe.jsp

<head>
    <link href="static/bootstrap-3.3.5-dist/css/bootstrap.css" rel="stylesheet" />
    <link href="static/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
    <link rel="stylesheet" href="static/bootstrap-select/bootstrap-select.min.css" />
</head>
<body>
	<div class="panel-body" style="padding-bottom:0px;">
		<div class="panel panel-default" style="margin:10px;">
			<div class="panel-heading">
				<span>查询条件</span>
			</div>
			<input id="query_dataSource" type="hidden"   value="${dataSource}">
			<input name="id"             type="hidden"   value="${id}">
			<div class="panel-body">
                                <!-- form表单 -->
				<form class="form-horizontal" id="formSearch">
					<div class="form-group" style="margin:0px">
						<!-- 一级选择框 -->
						<div class="col-sm-2" style="width:110px;">
							<label class="control-label" for="txt_search_departmentname">数据来源</label>
							<select class="form-control" id="dataSource">
								<option code="" value="" selected="selected">全部</option>
								<c:forEach var="dataSource" items="${dataSources }">
									<c:choose>
										<c:when test="${obj.dataSources == dataSource.dataSourceName}">
											<option code="${dataSource.dataSourceCode}" value="${dataSource.dataSourceName }" selected="selected">${dataSource.dataSourceName}</option>
										</c:when>
										<c:otherwise>
											<option code="${dataSource.dataSourceCode}" value="${dataSource.dataSourceName }">${dataSource.dataSourceName}</option>
										</c:otherwise>
									</c:choose>
								</c:forEach>
							</select>
						</div>
						<!-- 二级选择框 -->
						<div class="col-sm-2" style="width:110px;">
							<label class="control-label" for="txt_search_departmentname">信息来源</label>
							<select class="form-control" id="infoSource">
							  <option value="" selected="selected">全部</option>
							</select>
						</div>
						<div class="col-sm-1" style="text-align:left;">
							<button class="btn btn-primary" id="btn_query" type="button" style="margin-top:29px">查询</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<!-- 查询结果的列表显示位置 -->
		<div class=table-responsive">
			<table id="Table_queryList" class="table text-nowrap"></table>
		</div>
	</div>
	<script src="static/js/jquery-1.10.1.min.js"></script>
	<script src="static/bootstrap-3.3.5-dist/js/bootstrap.js"></script>
	<script src="static/bootstrap-table/bootstrap-table.js"></script>
        <script src="static/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
	<script src="static/bootstrap-select/bootstrap-select.js"></script>
	<script src="static/jsUtil/jquery.form.js"></script>
	<script src="static/js/zaiqing_shenhe.js"></script>
</body>

zaiqing_shenhe.js

$(function () {	
    //二级联动	绑定事件  :数据来源》信息来源
    $("#dataSource").change(function(){	
		var infoSourceArr=[
							{
								"全部":[
									"灾害大典",
									"灾情普查",
									"灾情直报",
									"网络媒体",
									"微博",
									"墨迹天气",
									"河北天气",
									"其他"
								]
							},
							{
								"互联网":[
									"网络媒体",
									"微博",
									"墨迹天气",
									"河北天气",
									"其他"
								]
							},
							{
								"气象部门":[
									"灾害大典",
									"灾情普查",
									"灾情直报",
									"其他"
								]
							}
						]
		var dataSourceVal=$("#dataSource").find("option:selected").val();//一级下拉框,选中值
		dataSourceVal  = dataSourceVal.replace( /^\s+|\s+$/g, "" );//去除字符中 空格
		var infoSource=$("#infoSource");
		for(var i in infoSourceArr){
			for(var j in infoSourceArr[i]){
				j  = j.replace( /^\s+|\s+$/g, "" );
				if(dataSourceVal==j){
					var infoSourceSecondArrVal=infoSourceArr[i][j];
				}
			}	
		}
		document.getElementById("infoSource").options.length = 1; //清空select标签中option选项=0,只留一项=1
		//根据一级下拉框选中值,加载相应的二级下拉框选项
		for (var k in infoSourceSecondArrVal){//(var k=0;k<infoSourceSecondArrVal.length;k++)则浏览器调试出错:Uncaught TypeError: Cannot read property 'length' of undefined
			infoSource.append('<option  value="'+infoSourceSecondArrVal[k]+'" >'+infoSourceSecondArrVal[k]+'</option>')
		}
	});
});


//查询》列表显示
var TableInit = function () {
	...
	//初始化Table
	oTableInit.Init = function (pageNumber) {
		...
                //得到查询的参数
		oTableInit.queryParams = function (params) {
			var temp = {   //这里的键的名字和控制器Controller里的变量名必须一致
				...
				dataSource: $("#dataSource").find("option:selected").val(),
				infoSource: $("#infoSource").find("option:selected").val(),
				...
			};
			...
		};
		$('#Table_queryList').bootstrapTable('destroy').bootstrapTable({
			...
		})
	};
	...
};

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值