다음 코드가 있습니다. 그리고 왜 그것이 한 방향으로 작용하지만 다른 방향으로 작용하지 않는지 궁금합니다.이상한 jQuery DataTables 초기화 동작
<!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Chart</title>
<link href="./css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="./js/jquery-3.1.0.min.js"></script>
<script src="./js/jquery.dataTables.min.js"></script>
<script>
/*
// THIS BLOCK DOES NOT WORK
var tbldata;
$(document).ready
(
function()
{
tbldata = $("#tbldata").DataTable();
}
);
*/
// THIS SINGLE LINE WORKS
var tbldata = $("#tbldata").DataTable();
</script>
</head>
<body>
<div>
<table id="tbldata">
<thead></thead>
<tbody></tbody>
</table>
</div>
</body>
</html>
작동하지 않는 것으로 표시된 블록의 주석을 제거하고 작동하는 한 줄을 주석 처리하면 다음과 같은 오류가 발생합니다. 옵션없이 DataTables 이니셜 라이저를 호출 할 때
jQuery.Deferred exception: Cannot read property 'aDataSort' of undefined TypeError: Cannot read property 'aDataSort' of undefined
at V (http://192.168.33.10:5000/static/js/jquery.dataTables.min.js:65:443)
at va (http://192.168.33.10:5000/static/js/jquery.dataTables.min.js:70:61)
at HTMLTableElement.<anonymous> (http://192.168.33.10:5000/static/js/jquery.dataTables.min.js:91:148)
at Function.each (http://192.168.33.10:5000/static/js/jquery-3.1.0.min.js:2:2815)
at r.each (http://192.168.33.10:5000/static/js/jquery-3.1.0.min.js:2:1003)
at r.m [as dataTable] (http://192.168.33.10:5000/static/js/jquery.dataTables.min.js:82:388)
at r.h.fn.DataTable (http://192.168.33.10:5000/static/js/jquery.dataTables.min.js:166:245)
at HTMLDocument.<anonymous> (http://192.168.33.10:5000/static/test.html:30:45)
at j (http://192.168.33.10:5000/static/js/jquery-3.1.0.min.js:2:29568)
at k (http://192.168.33.10:5000/static/js/jquery-3.1.0.min.js:2:29882) undefined
는 지금까지 내가 아는 한, 당신은 댓글을 달았 블록이 작동해야하며, 한 줄이 작동하지 않아야합니다. 이 주위의 다른 방법은 ** 이상한 ** –