1

我有一个按预期完美运行的 DataTable,但我在生成 JSON 文件时做了一些作弊。我希望一些记录链接到另一个页面,并通过将 href 标记包含到 JSON 中来实现。尽管这可行,但我真的不认为这是编写此代码的最佳方式,并且我认为这可能会导致将来更长的加载时间,届时数据库将充满数千条记录。

数据表代码:

 <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"
     }
 ]

谢谢!

4

0 回答 0