声明:以下仅是提供处理的方法,具体的操作方法需要根据自己的需求进行相应的处理。
前端保存对象数组作为参数:
<1>定义数据对象:
function dataObject(rowColPosition,content){
this.rowColPosition = rowColPosition;
this.content = content;
}
数据对象可根据当前需求自行设置。
<2>定义对象数组并填充对象数据:
function saveTableToExcel(){
var checkReportModelId = $("#tableExcel").children().first().children().first().children().first().attr("checkReportModelId");
var tableExcelSheetName = $("#tableExcel").children().first().children().first().children().first().text();
var $trs = $("#tableExcel").children().first().children();
var $tds;
var tableDatas = new Array();
var dataIndex = 0;
for(var i=1;i<$trs.length;i++){
$tds = $trs.eq(i).children();
for(var j=0;j<$tds.length;j++){
tableDatas[dataIndex++] = new dataObject($tds.eq(j).attr("rowColPosition"),$tds.eq(j).text());
}
}
return tableDatas;
}
<3>获取数据将对象数组作为参数传递:
var tableDatas = saveTableToExcel();
<!--通过ajax或者其他方式添加一个参数用来传递到后端-->
"tableDatas ":JSON.stringify(tableDatas)//对象数组转String
后端接收对象数组:
<1>定义实体类用于接收对象数组:
/**
*注:属性要与前端定义的对象属性对应
*/
package com.sn.entity;
public class tableDatasJSON {
private String rowColPosition;
private String content;
public String getRowColPosition() {
return rowColPosition;
}
public void setRowColPosition(String rowColPosition) {
this.rowColPosition = rowColPosition;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
<2>接收对象数组:
JSONArray tableDatasJSON = JSONArray.fromObject(tableDatas);
if(tableDatasJSON!=null && tableDatasJSON.size()>0){
List<com.sn.entity.tableDatasJSON> tableDatasJSONList = (List<com.sn.entity.tableDatasJSON>)JSONArray.toCollection(tableDatasJSON, com.sn.entity.tableDatasJSON.class);
//根据自己需求获取想要数据
}
补充Jquery版本下载:(仅供参考)
jquery 3.2.1:https://download.youkuaiyun.com/download/cevery/10871772
jquery 1.9.1:https://download.youkuaiyun.com/download/cevery/10871778