0

我正在使用Tabulator Plugin 将我的数据加载到我的 html 中。为此,我在我的 javascript 中使用此代码:

 var j = $( "#example-table" ).hasClass( "tabulator" )
  console.log(res["data"]);

  if (j) {
    $("#example-table").tabulator("destroy");


  }
  $("#example-table").tabulator({
    layout:"fitColumns"});

  //set new columns
  $("#example-table").tabulator("setColumns", res["column"]);

  //set new data
  $("#example-table").tabulator("setData", res["data"]);


  $("#download-xlsx").click(function(){
    $("#example-table").tabulator("download", "xlsx", "data.xlsx");
  });

  $("#download-csv").click(function(){
    $("#example-table").tabulator("download", "csv", "data.csv");
});

//trigger download of data.json file
$("#download-json").click(function(){
    $("#example-table").tabulator("download", "json", "data.json");
});

我在我的 html 中使用了这段代码:

    <div>
    <button class ="table-button" id ="download-xlsx">Download XLSX</button>
    <button class ="table-button" id ="download-csv">Download CSV</button>
    <button class ="table-button" id ="download-pdf">Download PDF</button>
    <button class ="table-button" id ="download-json">Download JSON</button>
    </div>

     <div id="example-table" style="margin-bottom: 100px; margin-top: 30px;" ></div>
    </div>

每次调用 ajax 时,这段代码都可以正常工作我使用 res["data"] 获取数据我将其放入制表符集数据函数中,并且它正在完美地加载我的数据。但是,当我在加载数据时第一次单击下载 Excel 时,我正在下载文件,但是当我点击并重新加载新数据时,它会下载三个文件或四个文件。我的问题是当我点击新的新数据时如何重置文件和下载队列。

4

1 回答 1

0

Tabulator 中没有下载队列,如果您单击该按钮,它将下载表格内容。

如果您正在发生多次下载,这表明您正在多次重新绑定单击事件,因此单击按钮会多次调用该函数。

于 2018-09-24T20:44:00.597 回答