JSON数据填充到页面表格 博客分类: 2017年7月 jsontablejs
程序员文章站
2024-03-11 22:54:13
...
后台返回到ajax的数据:
[{"deploymentId":"80001","id":"leave-16","name":"leave","version":16},{"deploymentId":"80015","id":"leave-17","name":"leave","version":17},{"deploymentId":"80022","id":"leave-18","name":"leave","version":18},{"deploymentId":"90001","id":"leave-19","name":"leave","version":19},{"deploymentId":"90012","id":"leave-20","name":"leave","version":20},{"deploymentId":"100001","id":"leave-21","name":"leave","version":21}]
前台页面:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <table id="myTable" cellpadding="1" cellspacing="0" border="1"> <caption align="top"> 流程管理 </caption> <thead> <tr> <th>流程ID</th> <th>流程名称</th> <th>流程版本</th> <th>操作</th> </tr> </thead> <tbody></tbody>
</table>
</body> </html> |
前端的js代码:(这里用的ajax返回给前台的json并做处理):
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$(function (){
$.ajax({ url : "/jbpm2web/jbpm/show?username=<%=session.getAttribute(" username ") %>", type : "get", success : function (data){ var obj = eval(data); var tbody = $('<tbody></tbody>'); $(obj).each(function (index){ var val = obj[index]; var tr = $('<tr></tr>'); tr.append('<td>' + val.id + '</td>' + '<td>' + val.name + '</td>' + '<td>' + val.version + '</td>' + '<td><a href="/jbpm2web/jbpm/delete?id=' + val.deploymentId + '" >删除流程</a>|<a href="/jbpm2web/jbpm/start?id=' + val.id + '&username=<%=session.getAttribute("username") %>">发起流程</a></td>'); tbody.append(tr);
}); $('#myTable tbody').replaceWith(tbody); } }); }); |