我使用struts2-json插件生成JSON数据和Ajax,用来自该JSON的数据(根据源)填充表(handsontable ).
现在,我需要使用JSON的Ajax从表中检索数据到Struts2 Action.首先,我已经使用JSON从Struts2 Action传递给Handsontable的数据实现了填充表,这非常简单且有效.但为什么保存不起作用,你可以在下面的附加代码中看到?
正如我在firebug中看到的那样发送了POST,并且在调试中,我的JSONSaveAction操作中检索到了请求,但是字段数据没有填充JSON数据,为什么?不应该通过struts2-json插件自动将数据绑定到java对象?我究竟做错了什么?
在handontable部分,该函数handsontable.getData()负责从表中获取整个数据.所以我这样使用它但没有成功:
$.ajax({
url: "../json/saveJSONDataAction.action",
data: {data: handsontable.getData()}, //returns all cells' data
dataType: 'json',
type: 'POST',
success: function (res) {
if (res.result === 'ok') {
$console.text('Data saved');
}
else {
$console.text('Save error');
}
}
});
Run Code Online (Sandbox Code Playgroud)
该函数handsontable.getData()实际上检索了我检查的所有数据,但是List<Report> data在我的JSONSaveAction操作中数据没有绑定到java对象.你知道为什么吗?
这是POST请求后我的表和firebug信息的屏幕截图:

@ParentPackage("json-default")
@Action(value="getJSONDataAction")
@Result(name="success", type="json")
public class JSONDataAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private List<Report> data = new ArrayList<Report>();
public JSONDataAction(){
data.add(new Report(1, "Chris", …Run Code Online (Sandbox Code Playgroud)