我有一个完美的DataTable,按照预期的方式运行,但我在生成JSON文件时做了一些作弊。我想要一些记录链接到另一个页面,并通过将href标记包含到JSON中来实现。虽然这有效,但我并不认为这是编码的最好方法,我认为这可能导致未来更大的加载时间,当db将填充数千条记录时。
DataTable代码:
<script type="text/javascript">
$(document).ready( function() {
var oTable = $('#alle_spellen').dataTable( {
"sAjaxSource": "json.php",
"aoColumns": [
{ "mData": "kaarting"},
{ "mData": "speler" },
{ "mData": "punten", "sClass" : "right",
"sType": "numeric",
"mRender": function ( data, type, full ) {
if(data > 0) return "<div class='positive'>" + data + "</div>";
return "<div class='negative'>" + data + "</div>";}
}],
})
} );
$(document).ready(function() {});
</script>
JSON文件(仅作为示例的2条记录):
[
{
"kaarting": "<a href="datatable_xtabelspel.php?id=id1" Text which includes id1 </a>",
"speler": "Arne",
"punten": "17"
},
{
"kaarting": "<a href="datatable_xtabelspel.php?id=id2" Text which includes id2 </a>",
"speler": "Filip",
"punten": "-7"
}
]
如何更改我的脚本以链接到相应的页面(包括db id),并拥有这样的JSON:
[
{
"kaarting": "Text which includes id1",
"speler": "Arne",
"punten": "17"
},
{
"kaarting": "Text which includes id2",
"speler": "Filip",
"punten": "-7"
}
]
谢谢!