注:该程序是将后台的数据一次性加载到页面内存中,再对内在中的数据进行分页
下载bigpage2.1.1-demo-swidget文件,并将相应的js,css,images添加到项目中
jsp页面中的关键代码:
<script type="text/javascript" src="js/jquery-1.6.1.js"></script>
<script type="text/javascript" src="js/jquery.bigpage.js"></script>
<script type="text/javascript">
var temp = setTimeout("fileData()",500); //根据本项目需求,在页面加载500毫秒后自动执行下面语句(不同项目可以根据自己的项目需求调整)
var data_ = null;
function fileData(){
$.getJSON("http://****:8888/weblog/home/historyTest",function(json){
alert(json[0]);
data_ = new Array(json.length);
alert(data_.length);
for(var i = 0; i < json.length; i ++){
data_[i] = json[i];
}
$("#dd").bigPage({data:data_,position:"both"});
});
}
</script>
</head>
<body>
<div style="95%" align="center" >
<table id="dd" class="tb1" cellSpacing=0 cellPadding=2 width="100%" align="right" border=0>
<thead>
<tr>
<th width="700px">问题频率排序</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</body>
该项目中List添加的是String类型,所以对jquery.bigpage.js做以下修改:
注:$.bigPage.addCssWidget();可以根据自己项目需求做出灵活的改动
//添加渲染table内容
$.bigPage.addCssWidget({
id:"appendToTable",
format :function($table){
var subData = $table.getSubData();
var $tBody = $table.find("tbody:first");
var trsArray = [];
for(var i=0;i<subData.length;i++){
var cellVaues = subData[i];
//alert("subData[" + i +"]:" + subData[i]);
trsArray.push("<tr><td>");
trsArray.push(subData[i]);
trsArray.push("</td></tr>");
// var trArray =[];
// trArray.push("<tr>");
// for(var j=0;j<cellVaues.length;j++){
// alert("cellVaues[" + j +"]:" + cellVaues[j]);
// trArray.push("<td>");
// trArray.push(cellVaues[j]);
// trArray.push("</td>");
// }
// trArray.push("</tr>");
// trsArray.push(trArray.join(""));
}
alert("trsArray:" + trsArray[0]);
$tBody.html(trsArray.join(""));
}
Struts2中action:
package com.iengine.action;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import org.apache.struts2.ServletActionContext;
import analyser.HighRateQuestion;
import analyser.TextFormalize;
import com.iengine.util.Constants;
import com.opensymphony.xwork2.ActionSupport;
public class HistoryTestAction extends ActionSupport{
private static final long serialVersionUID = 6234200825777300798L;
private ArrayList<String> result = new ArrayList<String>();
public String history(){
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html; charset=utf-8");
response.setHeader("pragma", "no-cache");
response.setHeader("cache-control", "no-cache");
TextFormalize.textFormativeTotal(Constants.configPath + "originalTemp",Constants.configPath + "formal/total.txt");
result=HighRateQuestion.questionFirstRoundSort(Constants.configPath + "formal/total.txt",2);
JSONArray jsonArray = JSONArray.fromObject(result);
try {
response.getWriter().print(jsonArray);
response.getWriter().close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(result);
return null;
}
public ArrayList<String> getResult() {
return result;
}
public void setResult(ArrayList<String> result) {
this.result = result;
}
}
效果图: