1.html文件
<li>
<label> 司法机构:</label>
<select id="chooseAgency" class="" name="chooseAgency" style=" 160px; height: 20px;"></select>
</li>
2.js方法
var getAgencyId=function(){ var agencyId=$("#chooseAgency option:selected").val(); if(agencyId==-1){ agencyId=""; } return agencyId; };
3.往select下拉框赋值的方法
function initAgency(){ var cAgency=$("#chooseAgency") ; $.ajax({ type: 'post', dataType: 'json', async: false, url: parent.baseUrl+"report/initAgency", success: function (result) { var size=result.length ; var opt='<option value="-1" selected="selected">显示全部</option>'; if(size==0){ cAgency.html(opt); return ; } $.each(result,function(i,item){ opt+='<option value="'+item.key+'" >'+item.name+'</option>'; }); cAgency.html(opt); return ; } }); }
4.控制器方法
@RequestMapping(value = "initAgency", method = RequestMethod.POST) @ResponseBody public List<TypeModel> reportAgency(@ModelAttribute("selectedAgency") SysAgencyDto selectedAgency){ Long agencyId= selectedAgency.getId(); List<TypeModel> dtoList=new ArrayList<TypeModel>();//当前机构数据放在第一个位置 List<SysAgency> all=new ArrayList<SysAgency>(); SysAgencyDtoAssembler dtoassembler=new SysAgencyDtoAssembler(); if(agencyId==0l){ all=sysAgencyService.findAll(null); }else{ SysAgency agency=sysAgencyService.findOne(agencyId); dtoList.add(dtoassembler.toDic(agency)); all=aucReportService.findAllSubAgency(all,agencyId); } for (SysAgency sysAgency : all) { dtoList.add(dtoassembler.toDic(sysAgency)); } return dtoList; }