table.getdata返回一个空字符串

时间:2019-01-23 13:37:41

标签: tabulator

我想在进行更改后将表保存到文本文件中。当我单击“保存”按钮时,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> 

1 个答案:

答案 0 :(得分:1)

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

var tbldata = table.getData();