$("#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();
}