$("#configCode").change(function(){
$("#configDtlCode").empty();//清空下拉框
$("<option value=''>--請選擇--</option>").appendTo("#configDtlCode");//添加下拉框的option
var id = $("#configCode").val();
$.ajax({
url: "<c:url value='/systemConfig/getDetail_'/>"+id,
type:'POST',
async:false,
dataType: 'json',
success: function(data){
if(data == null || data == "") return;
var optionStr = "";
$(data).each(function(idx,item){
optionStr +="<option value='"+item[1]+"'>"+item[2]+"</option>";
});
$(optionStr).appendTo("#configDtlCode");
}
});
});
@ResponseBody
@RequestMapping(value = "/getDetail_{id}",method = RequestMethod.POST,produces = "text/plain; charset=UTF-8")
public String getDetail(@PathVariable(value = "id") String baseCode) throws Exception{
String json="";
try {
json=sysConfigService.findConfigDtlBycode(baseCode);
} catch (Exception e) {
logger.error(e);
throw new RuntimeException(e);
}
return json;
}
@Override
public String findConfigDtlBycode(String code) throws Exception {
JSONArray json=null;
try {
List<BasicConfigDtlModel> list = sysConfigDao.findBasicConfigDtlById(code);
List<String[]> JsonList = new ArrayList<String[]>();
for (BasicConfigDtlModel basic : list) {
String[] strs = { basic.getId(),basic.getCode(),basic.getNameCn()};
JsonList.add(strs);
}
json = JSONArray.fromObject(JsonList);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
return json.toString();
}
本文介绍了一个使用Ajax技术实现的配置代码动态加载方案。当用户在前端页面选择特定配置代码时,系统通过Ajax发送异步请求到后端获取相关配置详情,并更新页面上的下拉菜单选项。后端采用Java技术栈,利用Spring框架处理请求并调用服务层方法来检索配置详情。

1223

被折叠的 条评论
为什么被折叠?



