html
<table class="table table-striped table-bordered">
<thead>
<tr>
<th class="center">序号</th>
<th class="center">附件</th>
</tr>
</thead>
<tbody id="sealListTbody"></tbody>
</table>
jquery
$(function(){
var data = '${jarray}';
var jsonobj= eval('(' + data + ')');//把json字符串解析为javascript对象
for(var i = 0; i < jsonobj.length; i++){
var tr = "<tr class='center'><td>"
+ (i + 1)
+ " <input type = 'checkbox' name='selecti' value ='"
+ jsonobj[i].id
+ "'></td><td><a href='sysformAction.do?method=showFile&id="
+ jsonobj[i].id
+ "'>"
+ jsonobj[i].fileName
+ "</a></td></tr>";
$("#sealListTbody").append(tr);
}
});
java
List<JSONObject> rslist = new ArrayList<JSONObject>();
for (int i = 0; i < attachlist.size(); i++) {
org.oa.pojos.File attach = (org.oa.pojos.File) attachlist
.get(i);
JSONObject obj = new JSONObject();
obj.accumulate("id", attach.getId());// 将list集合数据放到JSONObject对象中
obj.accumulate("fileName", attach.getFilename());
rslist.add(obj);// 数据存入集合中,集合中存放JSONObject对象
}
JSONArray jarray = JSONArray.fromObject(rslist);// 结果转化为json数组
request.setAttribute("jarray", jarray.toString());