下拉框多级联动

function getShelf(){
var storageId = $("#location").val();
//return alert(storageId);
$.ajax({
url:"${pageContext.request.contextPath}/asset/asset/getShelf?storageId="+storageId,
type:"get",
async:false,
timeout:"1000",
success:function(data){
$("#shelvesId option").remove();
$("#shelvesId").append("<option value='0'>--请选择--</option>");
if (data != 0) {
for ( var i = 0; i < data.length; i++) {
var shelvesId = data[i].shelvesId;
var shelname = data[i].shelname;
$("#shelvesId").append("<option value="+shelvesId+">" + shelname + "</option>");
}
}
},
error : function(XMLResponse) {
alert(XMLResponse.responseText);
}
});
}

服务端

//查询获取id下货架
@RequestMapping(value="getShelf")
public String getShelf(HttpServletRequest reuqest, HttpServletResponse response) throws Exception{
//格式
response.setContentType("text/json; charset=UTF-8");
//调用仓库并获取仓库ID
String storageId = reuqest.getParameter("storageId");
Integer id = Integer.parseInt(storageId);
PrintWriter out = null;
try{
out = response.getWriter();
}catch(Exception e){
e.printStackTrace();
}
JSONArray array = new JSONArray();
JSONObject member = null;
try{
//根据仓库的Id 来查找仓库下的所有货架信息
LmShelvesExample shelvesExample = new LmShelvesExample();
LmShelvesExample.Criteria criteria = shelvesExample.createCriteria();
if (StringUtils.isNotEmpty(id.toString()) && !"0".equals(id)){
criteria.andRemarksEqualTo(id.toString());
}
List<LmShelves> shelvesList = shelvesService.selectByExample(shelvesExample);
for(LmShelves shelf:shelvesList){
member = new JSONObject();
member.put("shelvesId", shelf.getShelvesId());
member.put("shelname", shelf.getShelname());
array.add(member);
}
}catch(Exception e){
e.printStackTrace();
}
out.print(array.toString());
return null;
}
posted @ 2018-01-08 14:55  一个写代码的人  阅读(991)  评论(0编辑  收藏  举报