EasyUI实现:combobox 实现下拉列表展示年份
1. jsp 页面:
<input title="年份" style="width: 99%;" type="text" name="feeDate" id="feeDate" value=""/> <script type="text/javascript"> //初始化数据 $(function(){ //年份初始化 $('#feeDate').combobox({ url:'orgbuild/party/djpartydues/djPartyDuesController/operation/queryYearList.json', valueField:'yearId', textField:'yearName' }); }); </script>
2. java代码
/** * 获取年份列表 * 当前年份及向前取10年的年份数据 */ @RequestMapping(value = "/operation/queryYearList") public ModelAndView queryYearList(HttpServletRequest request, HttpServletResponse response) throws Exception{ //获取当前年份 及前10年的记录 String newYear = DateUtils.getYear(); int currentYear = Integer.parseInt(newYear); String date = "["; for(int i=0; i<10; i++){ String yearId = Integer.toString(currentYear); String yearName = Integer.toString(currentYear)+"年"; date += "{\"yearId\":\"" + yearId + "\",\"yearName\":\"" + yearName + "\"}"; if(i<9){ date +=","; } currentYear--; } date += "]"; response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.write(date); out.close(); return null; }
//返回json // [{"yearId":"2017","yearName":"2017年"},{"yearId":"2016","yearName":"2016年"},{"yearId":"2015","yearName":"2015年"},{"yearId":"2014","yearName":"2014年"},{"yearId":"2013","yearName":"2013年"},{"yearId":"2012","yearName":"2012年"},{"yearId":"2011","yearName":"2011年"},{"yearId":"2010","yearName":"2010年"},{"yearId":"2009","yearName":"2009年"},{"yearId":"2008","yearName":"2008年"}]
展示效果: