DataTable:使用带有ajax.reload()的函数

时间:2015-03-06 16:53:58

标签: javascript jquery datatables datatables-1.10

我对方法ajax.reload()有些麻烦 - 没有任何反应。我已经使用此JavaScript进行了测试:

$(document).ready(function() {
    var table = $('#example').DataTable( {
        "ajax": {
            "async": false,
            "url": "arrays.txt",
            "dataSrc": function(json){return json;} // really necessary ?
        }
    } );

    $('#reload').click(function () {
        table.ajax.reload(function(data){
            console.log(data);
        }, false);
    } );
} );

arrays.txt内容:

[
        [
      "Tiger Nixon",
      "System Architect",
      "Edinburgh",
      "5421",
      "2011/04/25",
      "$320,800"
    ],
    [
      "Garrett Winters",
      "Accountant",
      "Tokyo",
      "8422",
      "2011/07/25",
      "$170,750"
    ]
]

和html内容:

<button id="reload">reload</button>
<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
</table>

如果我改变了你的&#34;代码(dataTables.js)到

if(callback){
  var api = new _Api( settings );
  callback( api.ajax.json() );
}

而不是

if(callback){
  var api = new _Api( settings );
  api.one( 'draw', function(){
    callback( api.ajax.json() );
  });
}

它对我有用......

实际上,如果您再次单击该按钮,它会起作用,但这不是解决方案。

0 个答案:

没有答案
相关问题