嗨,我是 jqGrid 的新手。我正在使用 jqGrid 4.4。我已经成功地使用了 Oleg 的方法
在本地添加行。我面临2个问题
- 未添加到末尾的行,我该如何实现?
- 我通过单击按钮发送所有行,如下所示:
我总是在错误块中收到警报?
$("#sendButton").click(function(){
var gridData = jQuery("#list").getRowData();
var myJSONString = JSON.stringify(gridData);
var postData = myJSONString.replace(/[\"]/g, '\"');
alert("JSON serialized jqGrid data:\n" + postData);
$.ajax({
type: "POST",
url: CONTEXT_ROOT+"/json",
data : postData,
dataType:"json",
contentType: "application/json; charset=utf-8",
success: function(response, textStatus, xhr) {
alert("success");
},
error: function(xhr, textStatus, errorThrown) {
alert("error:"+errorThrown+" textStatus : "+textStatus);
}
});
});
不确定保存在 java 控制器中后需要返回什么。这是控制器中的代码。我也尝试将返回作为 void 但结果相同。还有一种更好的方法可以将来自 jsp 的 json 对象列表绑定到域对象列表。当只有一个对象(例如使用 @RequestBody 的表单中的对象)时,我尝试过 Binding,如中所述
http://blog.springsource.org/2010/01/25/ajax-simplifications-in-spring-3-0/
@RequestMapping(value = "/json", method = RequestMethod.POST)
public ModelAndView saveNewCasePackOptions(@RequestBody List<Map> json) {
for(Map mJson : json){
String idCasePkOptions = (String)mJson.get("idCasePackOptions");
Long idCasePackOptions = (idCasePkOptions.isEmpty())?null:new Long(idCasePkOptions);
Short cypharecommended = new Short((String)mJson.get("cypharecommended"));
Short distributorapproved = new Short((String)mJson.get("distributorapproved"));
String heightStr = (String)mJson.get("height");
Double height = (heightStr.isEmpty())?null:new Double(heightStr);
String lengthStr = (String)mJson.get("length");
Double length = (lengthStr.isEmpty())?null:new Double(lengthStr);
String weightStr = (String)mJson.get("height");
Double weight = (weightStr.isEmpty())?null:new Double(weightStr);
String widthStr = (String)mJson.get("width");
Double width = (widthStr.isEmpty())?null:new Double(widthStr);
String stateString = (String)mJson.get("statuscode");
stateString = (stateString.contains("Green"))?"1":"0";
Short statuscode = new Short(stateString);
CasePackOptions casePkOpt = new CasePackOptions(idCasePackOptions, cypharecommended, distributorapproved, height, length, statuscode, weight, width);
System.out.println(casePkOpt);
casePackOptionsService.save(casePkOpt);
}
ModelAndView mav = new ModelAndView();
mav.setViewName("casepackoptions/listPage1.jsp");
return mav;
}
任何帮助都感激不尽。