JavaScript实现省市区三级联动
本文实例为大家分享了JavaScript实现省市区三级联动的具体代码,供大家参考,具体内容如下
首先是js
$(document).ready(function(){ getErpMarketByParentCode(0,'province',province); getErpMarketByParentCode(province,'city',city); getErpMarketByParentCode(city,'area',area); getErpMarketByParentCode(area,'market',market); $('#city').append($('
然后是后台方法
@RequestMapping(value="/getErpMarketByParentCode") publicModelAndViewgetErpMarketByParentCode(HttpServletRequestrequest,HttpServletResponseresponse)throwsException{ Stringcode=request.getParameter("code"); ListerpMarketList=erpMarketService.getErpMarketListByParentCode(code); JSONObjectjsonObject=newJSONObject(); jsonObject.put("erpMarketList",erpMarketList); response.getWriter().write(jsonObject.toString()); returnnull; }
service方法,是从内从中获取省市区这张表
publicListgetErpMarketListByParentCode(StringparentCode){ HashtableerpMarketTable=LoadOnStartService.erpMarketTable;//从内存中获取这张表 List erpMarketList=newArrayList (); Iteratorits=erpMarketTable.keySet().iterator(); while(its.hasNext()){ Stringkey=Util.getString(its.next()); ErpMarketerpMarket=(ErpMarket)erpMarketTable.get(key); if(parentCode.equals(erpMarket.getParentCode())){ erpMarketList.add(erpMarket); } } returnerpMarketList; }
省市区的实体类
packagecom.erp.entity; /** *ErpMarketentity. * *@authorMyEclipsePersistenceTools */ publicclassErpMarketimplementsjava.io.Serializable{ //Fields privateStringcode; privateStringshortCode; privateStringname; privateStringlevel; privateStringparentCode; //Constructors /**defaultconstructor*/ publicErpMarket(){ } /**fullconstructor*/ publicErpMarket(StringshortCode,Stringname,Stringlevel,StringparentCode){ this.shortCode=shortCode; this.name=name; this.level=level; this.parentCode=parentCode; } //Propertyaccessors publicStringgetCode(){ returnthis.code; } publicvoidsetCode(Stringcode){ this.code=code; } publicStringgetShortCode(){ returnthis.shortCode; } publicvoidsetShortCode(StringshortCode){ this.shortCode=shortCode; } publicStringgetName(){ returnthis.name; } publicvoidsetName(Stringname){ this.name=name; } publicStringgetLevel(){ returnthis.level; } publicvoidsetLevel(Stringlevel){ this.level=level; } publicStringgetParentCode(){ returnthis.parentCode; } publicvoidsetParentCode(StringparentCode){ this.parentCode=parentCode; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。