table.getdata returns 一个空字符串

table.getdata returns an empty string

我想在更改后将 table 保存到文本文件。当我点击保存按钮时,tbldata 是空的,我的文本文件被覆盖并变成空白。

我用以下方法测试了按钮:var tbldata = JSON.stringify([{"id":1, "name":"Bob"}]) 并且它有效。

我假设我使用 table.getData 不正确。 var tbldata = table.getdata 应该位于我的按钮功能的何处以及如何定位?

我在文档中找不到具体示例

 <button class="button" id="save-data" >Save Data</button>
 
    <script>
        //create Tabulator on DOM element
        var table = new Tabulator("#meetinfo-table", {
      height:200, // set height of table (in CSS or here)
        selectable:true, //make rows selectable        
      layout:"fitDataFill",//fit columns to fit data and width of table (optional)
  //Sort data decending
  initialSort:[
   {column: "meetdate", dir:"desc"}],
  //Define Table Columns   
  columns:[ 
       {title:"Meeting Date", field:"meetdate", width:150, editor:"input"},
       {title:"Topic", field:"topic", align:"left", editor:"input"},
       {title:"Speaker", field:"speaker", editor:"input"},
       {title:"Room", field:"room", editor:"input"},
         {title:"CE", field:"ce", align:"left", editor:"input"},
       {title:"RSVP Survey Code", field:"rsvpcode",editor: "input"},   
       {title:"RSVP Due Date", field:"rsvpduedate", editor:"input"},
      ], 
         }); 
                     
        //Saves entire table to JSON encoded string
  var button = document.getElementById("save-data");
  button.addEventListener("click", function(){
    
  var tbldata = table.getdata;
    
  var request= new XMLHttpRequest();   // new HttpRequest instance 
  request.open("POST", "process.php");
  request.setRequestHeader("Content-type", "application/json");
  //request.send(tbldata);
  });
  
  //loads data into the table
  table.setData('meetinfo_array.txt');
     </script> 

那里有两个问题,是 getData 而不是 getdata 并且您实际上并没有调用该函数,因为您在函数名称后缺少括号。应该是:

var tbldata = table.getData();