网上搜索,官网也看了,没找到解决方法,求助。<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AdminLTE 2 | Dashboard</title>
<link rel="stylesheet" href="http://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
</head>
<body>
<table id="example1" class="display" style="width:100%">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
<script>
//第一次加载的数据
var wjson=[{"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "机箱门被打开","AlarmType": "6","OccurTime": "100304","OccurDate": "20190919"}, {"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "机箱门关闭","AlarmType": "6","OccurTime": "100351","OccurDate": "20190919"}, {"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "机箱门被打开","AlarmType": "6","OccurTime": "100403","OccurDate": "20190919"}, {"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "机箱门关闭","AlarmType": "6","OccurTime": "100420","OccurDate": "20190919"}]
//第二次要加载的数据
var wjson2=[{"DeviceModel": "测试数据","DeviceID": "7","AlarmDesc": "测试数据","AlarmType": "6","OccurTime": "100304","OccurDate": "20190919"}, {"DeviceModel": "测试数据2","DeviceID": "7","AlarmDesc": "测试数据2","AlarmType": "6","OccurTime": "100351","OccurDate": "20190919"}, {"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "测试数据2","AlarmType": "6","OccurTime": "100403","OccurDate": "20190919"}, {"DeviceModel": "测试数据3","DeviceID": "7","AlarmDesc": "测试数据3","AlarmType": "6","OccurTime": "100420","OccurDate": "20190919"}]$(document).ready(function() {
$('#example2').DataTable({
'paging' : true,
'lengthChange': false,
'searching' : true,
'ordering' : true,
'info' : true,
'autoWidth' : false,
'processing': true,
'destroy':true
})
var tableww = $('#example1').DataTable( {
data:wjson, //第一次加载的数据
"columns": [
{ "data": "DeviceModel" },
{ "data": "DeviceID" },
{ "data": "AlarmDesc" },
{ "data": "AlarmType" },
{ "data": "OccurTime" },
{ "data": "OccurDate" }
]
} );
} );
//5秒后测试加载新的数据。
setTimeout(function(){
alert("aaa");
var logtable = $('#example1').DataTable();
logtable.clear().draw(); //清理掉第一次的数据
//logtable.ajax.reload();
newload(); //加载新的数据
}, 5000);
function newload(){
$('#example1').DataTable({
data:wjson2, //新数据
"columns": [
{ "data": "DeviceModel" },
{ "data": "DeviceID" },
{ "data": "AlarmDesc" },
{ "data": "AlarmType" },
{ "data": "OccurTime" },
{ "data": "OccurDate" }
]
} );
}
</script>
</body>
</html>现在第一次加载的数据没问题,但是想重新加载第二次的数据,总是没法实现,求助下。
<head>
<meta charset="UTF-8">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AdminLTE 2 | Dashboard</title>
<link rel="stylesheet" href="http://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
</head>
<body>
<table id="example1" class="display" style="width:100%">
<thead>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
<script>
//第一次加载的数据
var wjson=[{"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "机箱门被打开","AlarmType": "6","OccurTime": "100304","OccurDate": "20190919"}, {"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "机箱门关闭","AlarmType": "6","OccurTime": "100351","OccurDate": "20190919"}, {"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "机箱门被打开","AlarmType": "6","OccurTime": "100403","OccurDate": "20190919"}, {"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "机箱门关闭","AlarmType": "6","OccurTime": "100420","OccurDate": "20190919"}]
//第二次要加载的数据
var wjson2=[{"DeviceModel": "测试数据","DeviceID": "7","AlarmDesc": "测试数据","AlarmType": "6","OccurTime": "100304","OccurDate": "20190919"}, {"DeviceModel": "测试数据2","DeviceID": "7","AlarmDesc": "测试数据2","AlarmType": "6","OccurTime": "100351","OccurDate": "20190919"}, {"DeviceModel": "HD-4CT","DeviceID": "7","AlarmDesc": "测试数据2","AlarmType": "6","OccurTime": "100403","OccurDate": "20190919"}, {"DeviceModel": "测试数据3","DeviceID": "7","AlarmDesc": "测试数据3","AlarmType": "6","OccurTime": "100420","OccurDate": "20190919"}]$(document).ready(function() {
$('#example2').DataTable({
'paging' : true,
'lengthChange': false,
'searching' : true,
'ordering' : true,
'info' : true,
'autoWidth' : false,
'processing': true,
'destroy':true
})
var tableww = $('#example1').DataTable( {
data:wjson, //第一次加载的数据
"columns": [
{ "data": "DeviceModel" },
{ "data": "DeviceID" },
{ "data": "AlarmDesc" },
{ "data": "AlarmType" },
{ "data": "OccurTime" },
{ "data": "OccurDate" }
]
} );
} );
//5秒后测试加载新的数据。
setTimeout(function(){
alert("aaa");
var logtable = $('#example1').DataTable();
logtable.clear().draw(); //清理掉第一次的数据
//logtable.ajax.reload();
newload(); //加载新的数据
}, 5000);
function newload(){
$('#example1').DataTable({
data:wjson2, //新数据
"columns": [
{ "data": "DeviceModel" },
{ "data": "DeviceID" },
{ "data": "AlarmDesc" },
{ "data": "AlarmType" },
{ "data": "OccurTime" },
{ "data": "OccurDate" }
]
} );
}
</script>
</body>
</html>现在第一次加载的数据没问题,但是想重新加载第二次的数据,总是没法实现,求助下。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货