我想将我的 JSON 列表包含到数据表插件表中,我有代码,但有些东西不工作;/也许你会帮忙 :] 我有显示标题和构建表格的代码 - 它工作正常,但有些东西是当我将脚本包含到代码中时出错;/数据表版本 1.9.4
代码:
<html>
<head>
<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/media/images/favicon.ico" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<style type="text/css" title="currentStyle">
@import "css/table.css";
</style>
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
jQuery.fn.dataTableExt.oSort['numeric-comma-asc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['numeric-comma-desc'] = function(a,b) {
var x = (a == "-") ? 0 : a.replace( /,/, "." );
var y = (b == "-") ? 0 : b.replace( /,/, "." );
x = parseFloat( x );
y = parseFloat( y );
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
$(document).ready(function() {
$('#example').dataTable( {
"aoColumns": [
null,
null,
null,
{ "sType": "numeric-comma" },
null
]
} );
} );
</script>
<script>
$(document).ready(function() {
//code here
var jsondata=$.parseJSON('{"response":[["name0","id0","amt0"],["name1","id1","amt1"]]}');
$.each(jsondata.response, function(i, d) {
var row='<tr>';
$.each(d, function(j, e) {
row+='<td>'+e+'</td>';
});
row+='</tr>';
$('#example').append(row);
});
});
</script>
</head>
<body id="dt_example">
<div id="container">
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr><th>header1</th><th>header2</th><th>header3</th></tr>
</thead>
</table>
</div>
</div>
</body>
</html>