在employee实体中保存的是proviceId,cityId,areaId。
应用s标签的编辑页面:
<SCRIPT type="text/javascript"> $(function(){ $("#proId").change(function(){ var proId = $("#proId").val(); $("#cityId").empty(); $("#areaId").empty(); $.ajax({ url:"empjson!querycity.action", type:"POST", dataType:"json", data:{"parentId":proId}, success:function(listcity){ for(var i=0;i<listcity.length;i++){ $("#cityId").append("<option value='"+listcity[i].addressId+"'>"+listcity[i].addressName+"</option>"); } }, error:function(){alert("error");} }); }); $("#cityId").change(function(){ var cityId = $("#cityId").val(); $("#areaId").empty(); $.ajax({ url:"empjson!queryarea.action", type:"POST", dataType:"json", data:{"cityId":cityId}, success:function(listcity){ for(var i=0;i<listcity.length;i++){ $("#areaId").append("<option value='"+listcity[i].addressId+"'>"+listcity[i].addressName+"</option>"); } }, error:function(){alert("error");} }); }); }); </SCRIPT> </head> <body> <form action="emp!editSave.action" method="post"> <table> <tr> <td>empname:</td> <td><input type="text" name="employee.employeeName" value="${employee.employeeName}"/></td> </tr> <tr> <td>department:</td> <td> <s:select list="listdep" listKey="departmentId" listValue="departmentName" name="employee.department.departmentId"></s:select> </td> </tr> <tr> <td>department:</td> <td> <s:select list="listdep" listKey="departmentId" listValue="departmentName" name="employee.department.departmentId"></s:select> </td> </tr> <tr> <td>provice:</td> <td><s:select id = "proId" list="listpro" listKey="addressId" listValue="addressName" name="employee.proviceId"></s:select></td> </tr> <tr> <td>city:</td> <td> <s:select id = "cityId" list="listcity" listKey="addressId" listValue="addressName" name="employee.cityId"/> </td> </tr> <tr> <td>area:</td> <td> <s:select id = "areaId" list="listarea" listKey="addressId" listValue="addressName" name="employee.areaId"/> </td> </tr> <tr><td><input type="submit" value="editSave"></td></tr> </table> </form>
在Action中,editPage的方法:
public String editPage(){
employee = employeeService.queryById(id);
listpro = employeeService.queryPro();
listcity = employeeService.queryCity(employee.getProviceId());
listarea = employeeService.queryArea(employee.getCityId());
listdep = employeeService.queryDepList();
return "editPage";
}
在显示select下的option
var pro = $("#proId").find("option:selected").val();