Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 制表器-如何提取数据并另存为json对象_Javascript_Jquery_Tabulator - Fatal编程技术网

Javascript 制表器-如何提取数据并另存为json对象

Javascript 制表器-如何提取数据并另存为json对象,javascript,jquery,tabulator,Javascript,Jquery,Tabulator,在jquery/javascript中,有没有办法将制表器表中的所有数据保存到变量中? 我注意到他们有一个 table.downloadToTab("json"); 方法,这很酷,但我不想打开新的浏览器,我只想保存到一个变量 我知道我可以编写自己的javascript/jquery代码来循环遍历行和单元格,但看起来它们并没有使用带有和的传统表,但所有内容都有特定的类名 例如,这是为制表器表格中的一行数据创建的所有HTML: <div class="tabulator-row tabula

在jquery/javascript中,有没有办法将制表器表中的所有数据保存到变量中? 我注意到他们有一个

table.downloadToTab("json");
方法,这很酷,但我不想打开新的浏览器,我只想保存到一个变量

我知道我可以编写自己的javascript/jquery代码来循环遍历行和单元格,但看起来它们并没有使用带有
的传统表,但所有内容都有特定的类名

例如,这是为制表器表格中的一行数据创建的所有HTML:

<div class="tabulator-row tabulator-selectable tabulator-row-odd" role="row" style="padding-left: 30px;">
   <div class="tabulator-cell tabulator-row-handle tabulator-frozen tabulator-frozen-left" role="gridcell" title="" style="width: 30px; position: absolute; left: 0px; height: 29px;">
      <div class="tabulator-row-handle-box">
         <div class="tabulator-row-handle-bar"></div>
         <div class="tabulator-row-handle-bar"></div>
         <div class="tabulator-row-handle-bar"></div>
      </div>
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="id" title="" style="width: 150px; height: 29px;">
      2134561
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="first_name" tabindex="0" title="" style="width: 150px; height: 29px;">
      jane
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="last_name" tabindex="0" title="" style="width: 150px; height: 29px;">
      doe
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="company" tabindex="0" title="" style="width: 150px; height: 29px;">
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="email" tabindex="0" title="" style="width: 150px; height: 29px;">
      janedoe@testing.ca
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="title" tabindex="0" title="" style="width: 150px; height: 29px;">
      &nbsp;
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="registered" title="" style="width: 150px; height: 29px;">
      &nbsp;
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="speak" aria-checked="false" title="" style="width: 167px; text-align: center; height: 29px;">
      <svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve">
         <path fill="#CE1515" d="M22.245,4.015c0.313,0.313,0.313,0.826,0,1.139l-6.276,6.27c-0.313,0.312-0.313,0.826,0,1.14l6.273,6.272  c0.313,0.313,0.313,0.826,0,1.14l-2.285,2.277c-0.314,0.312-0.828,0.312-1.142,0l-6.271-6.271c-0.313-0.313-0.828-0.313-1.141,0  l-6.276,6.267c-0.313,0.313-0.828,0.313-1.141,0l-2.282-2.28c-0.313-0.313-0.313-0.826,0-1.14l6.278-6.269  c0.313-0.312,0.313-0.826,0-1.14L1.709,5.147c-0.314-0.313-0.314-0.827,0-1.14l2.284-2.278C4.308,1.417,4.821,1.417,5.135,1.73  L11.405,8c0.314,0.314,0.828,0.314,1.141,0.001l6.276-6.267c0.312-0.312,0.826-0.312,1.141,0L22.245,4.015z"></path>
      </svg>
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="paid" aria-checked="false" title="" style="width: 167px; text-align: center; height: 29px;">
      <svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve">
         <path fill="#CE1515" d="M22.245,4.015c0.313,0.313,0.313,0.826,0,1.139l-6.276,6.27c-0.313,0.312-0.313,0.826,0,1.14l6.273,6.272  c0.313,0.313,0.313,0.826,0,1.14l-2.285,2.277c-0.314,0.312-0.828,0.312-1.142,0l-6.271-6.271c-0.313-0.313-0.828-0.313-1.141,0  l-6.276,6.267c-0.313,0.313-0.828,0.313-1.141,0l-2.282-2.28c-0.313-0.313-0.313-0.826,0-1.14l6.278-6.269  c0.313-0.312,0.313-0.826,0-1.14L1.709,5.147c-0.314-0.313-0.314-0.827,0-1.14l2.284-2.278C4.308,1.417,4.821,1.417,5.135,1.73  L11.405,8c0.314,0.314,0.828,0.314,1.141,0.001l6.276-6.267c0.312-0.312,0.826-0.312,1.141,0L22.245,4.015z"></path>
      </svg>
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
   <div class="tabulator-cell" role="gridcell" tabulator-field="example" title="" style="width: 167px; height: 29px;">
      <a href="mailto://email" target="_blank">janedoe@testing.ca</a>
      <div class="tabulator-col-resize-handle"></div>
      <div class="tabulator-col-resize-handle prev"></div>
   </div>
</div>

2134561
简
雌鹿
janedoe@testing.ca
很多html! 但是我可以写代码。。。我只是想知道是否有更好的方法。

您可以使用制表器的方法:

这将以2D数组的形式返回表的所有数据。如果只想获取当前筛选的数据(用户可见),则将
true
作为参数传递:

var array = table.getData(true);
如果您需要以某种方式传输/保存此数据,您可以使用本机函数生成JSON:

var json = JSON.stringify(array);
您可以使用制表器的方法:

这将以2D数组的形式返回表的所有数据。如果只想获取当前筛选的数据(用户可见),则将
true
作为参数传递:

var array = table.getData(true);
如果您需要以某种方式传输/保存此数据,您可以使用本机函数生成JSON:

var json = JSON.stringify(array);

您可以使用
table.getData()
以2D数组的形式获取数据,如果表中的数据经过筛选,是否可以通过任何方式获取?getData()似乎要获取原始数据。。。但是我只想获取用户当前正在查看的内容。当然,您可以将
true
作为参数传递,以便只获取过滤后的数据。我认为制表器也有json导出器(除了csv、xlsx、pdf)您还可以指定要下载的列以及每个列的下载标题)…请参阅,您可以使用
table.getData()以2D数组的形式获取数据。如果表中的数据已被过滤,是否可以通过任何方式获取数据?getData()似乎要获取原始数据。。。但是我只想获取用户当前正在查看的内容。当然,您可以将
true
作为参数传递,以便只获取过滤后的数据。我认为制表器也有json导出器(除了csv、xlsx、pdf)您还可以指定要下载的列以及每个列的下载标题)…请参阅!正是我想要的。太好了!正是我想要的。