table数据如何通过ajax方式加载?
来源:互联网 发布:我的世界编程网站 编辑:程序博客网 时间:2024/05/01 14:03
首先在jsp页面设定一个table骨架,首先把该table的display属性设置为none,这样在加载页面的时候就不会显示出来,代码如下
<table id="generatedTable" style ="border=2; display: none;">
<thead>
<tr>
<th style='width:10%;'>表头1</th>
<th style='width:15%;'>表头2</th>
<th style='width:10%;'>表头3</th>
<th style='width:10%;'>表头4</th>
<th style='width:3%;'>表头4</th>
</tr>
</thead>
<tbody>
<tr id="cloneTr">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
然后根据这个骨架用ajax来把动态生成table的各个行,并把后台数据添加到table中
ajaxPost({
type:"GET",
url:"<c:url value='/logDetails.auth'/>",
data:"datas="+datas;//要发送的数据
//object是后台传过来的java list数据集合
success:function(objects){
//1,获取上面id为cloneTr的tr元素
var tr = $("#cloneTr");
$.each(objects, function(index,item){
//克隆tr,每次遍历都可以产生新的tr
var clonedTr = tr.clone();
var _index = index;
//循环遍历cloneTr的每一个td元素,并赋值
clonedTr.children("td").each(function(inner_index){
//根据索引为每一个td赋值
switch(inner_index){
case(0):
$(this).html(_index + 1);
break;
case(1):
$(this).html(item.caller);
break;
case(2):
$(this).html(item.imsi);
break;
case(3):
$(this).html(item.imei);
break;
case(4):
$(this).html(item.osid);
break;
}//end switch
});//end children.each
//把克隆好的tr追加原来的tr后面
clonedTr.insertAfter(tr);
});//end $each
$("#cloneTr").hide();//隐藏id=clone的tr,因为该tr中的td没有数据,不隐藏起来会在生成的table第一行显示一个空行
$("#generatedTable").show();
}//end success
});//end ajaxpost
- table数据如何通过ajax方式加载?
- bootStrap table+ajax加载数据
- SpringMvc中如何通过Ajax方式提交对象数据
- JQuery Ajax动态加载Table数据
- bootstrap table通过ajax获取后台数据展示在table
- bootstrap-table插件数据加载方式
- highcharts(1)------- 通过 Ajax 加载数据
- Echarts通过Ajax实现动态数据加载
- 通过Ajax方式绑定select选项数据
- easyui datagrid如何加载通过ajax获得的json格式的数据
- Yii: 如何在CGridView通过Ajax方式刷新数据后执行JS脚本
- 关于如何将table中的td标签转换成input标签以及将修改的数据通过ajax保存服务器
- Struts2中使用ajax+json方式批量删除table数据
- 如何通过sqlite加载数据到tableview
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)
- mui上拉加载通过ajax获取数据,实现分页
- ECharts通过Ajax动态加载数据到图表
- Android开发学习之路--Activity之生命周期
- highchart 时间轴 固定起始和结束值
- GDB查看cpu占用100%
- MySql中in和exists效率
- 排序二之冒泡排序
- table数据如何通过ajax方式加载?
- Android 打jar包流程
- AsyncTask简单使用
- 矩阵的鞍点
- 合并排序
- oracle insert select 语句中 select数量与insert数量不一致 bug(咋个办呢 zgbn)
- 常用正则表达式
- 5.6.2 视图对性能的影响
- MySQL 主从复制