需要代码改进,谢谢
当前加载/显示数据到页面的方式是:
$.getJSON('${cp}/'+url+'/'+myCode, function(response){
$.each(response, function(index, item){
switch(index) {
case "code":
$("#code").val(item);
break;
case "name":
$("#name").val(item);
break;
case "street1":
$("#street1").val(item);
break;
case "street2":
$("#street2").val(item);
break;
case "postalCode":
$("#postalCode").val(item);
break;
}
});//end of each
});//end of getJson
控制器代码是:
@RequestMapping(value="url/{myCode}", method=RequestMethod.GET)
public @ResponseBody Supplier getSupplier(@PathVariable("myCode")
Integer myCode, HttpSession session) {
setTable();
Supplier supp = srvSupplier.get(myCode);
return supp;
}
感谢必须点击按钮
答案 0 :(得分:3)
这个怎么样:
$.each(response, function( key, item ){
$("#" + key).val(item);
});