下拉框中的值从数据库动态获取


以t_crash_log表中的三个字段即手机类型、运营商和应用版本作为查询字段,查询字段的值即是我们要从数据库中动态获取放在下拉框中的。

部分代码如下:


1. jsp中定义三个select标签

手机类型: 
运营商: 
应用版本: 



2.js

	/**获取供查询的下拉列表框选项值 */
	function getQueryCrashLog(){
		var optionsDev="";
		var optionsNet="";        //该字段含有null值
		var optionsApp="";
		   $.ajax({
				async : false,
				cache:false,
				type: 'POST',
				dataType : "json",
				url: '<%=request.getContextPath()%>/crashLog/getQueryCrashLog.do',  //请求的路径
				success:function(data){												//controller层传过来的map
			   		 for(var i=0;i"+deviceSubList[j]+"";
			   				}
			   			}
			   			if(data[i].networkSubList==networkSubList){
			   				for(var j=0;j"+networkSubList[j]+"";
			   				}
			   			}
			   			 if(data[i].appSubList==appSubList){
			   			 	for(var j=0;j"+appSubList[j]+"";
			   			 	}
			   		 	}
		   			} 
			   	 } 
			});
		   $("#deviceModel").html(optionsDev);
		   $("#networkOperatorName").html(optionsNet);
		   $("#appVersion").html(optionsApp);
	}



3.controller层

	/**
	 * 根据手机类型、运营商名称、应用版本名称获取查询字段下拉框的选项值
	 * @param 
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping("/getQueryCrashLog")
	public void getQueryCrashLog(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setContentType("text/html;charset=UTF-8");
		
		Map> map = new HashMap>();
		List deviceModelList = crashLogBiz.getQueryCrashLogDevice();
		List networkOperatorNameList=crashLogBiz.getQueryCrashLogNetWork();
		List appVersionList = crashLogBiz.getQueryCrashLogApp();
		
		List deviceSubList=new ArrayList();
		List networkSubList=new ArrayList();
		List appSubList = new ArrayList();
		for(int i=0;i15){										//切取手机类型字符串
				String deviceSubStr=deviceStr.substring(0,15)+"...";
				deviceSubList.add(i, deviceSubStr);
			}
			else		
				deviceSubList.add(i, deviceStr);
			
		}
		
		for(int i=0;i15){										//切取运营商字符串
				String networkSubStr=networkStr.substring(0,15)+"...";
				networkSubList.add(i, networkSubStr);
			}
			else		
				networkSubList.add(i, networkStr);
			
		}
		
		for(int i=0;i15){										//切取应用版本字符串
				String appSubStr=appStr.substring(0,15)+"...";
				appSubList.add(i, appSubStr);
			}
			else		
				appSubList.add(i, appStr);
			
		}
		
		
		map.put("deviceSubList", deviceSubList);
		map.put("networkSubList", networkSubList);
		map.put("appSubList", appSubList);
		
		JSONArray jArray=JSONArray.fromObject(map);
		response.getWriter().print(jArray);
	
	}	


                                                   

你可能感兴趣的:(js)