javascript - 如何将 handsontable 数据传输到同一页面上的不同 JavaScript?

标签 javascript arrays handsontable

这是 jsfiddle 的链接handsontable 的代码。按下按钮时,数据集将转到控制台。我的网页上有两段不同的 JavaScript 代码。其中之一包含 handsontable我如何将数据传输(转储)到属于不同脚本片段(而不是控制台)的数组?有没有什么方法可以创建一个static数组所有脚本(如 Java)? 这是方案:

<div id="mytable" class="handsontable"> </div>
<script>
// Here the user inserts the data to the handsontable. As she presses the button, data should go to the second piece of script.
</script>

...

<div id="target" class=""> </div>
<script>
//the target array is here, and it needs to be filled with the data from the above piece of script as the button is pressed.
</script>

最佳答案

有很多方法可以做到,例如:

1.) 创建全局变量来保存数据

<div id="mytable" class="handsontable"> </div>

<script>
 // set data
  window.data = getCarData(); 

  $("#example1").handsontable({
     data:  window.data
  });
</script>

<div id="target" class="class"> </div>

<script>
  //get data 
  var array = window.data;
</script>

2.) 如果您使用 jQuery:

// you can bind data to element
$('table').data('key', 'value');

// and then get it
$('table').data('key');

关于javascript - 如何将 handsontable 数据传输到同一页面上的不同 JavaScript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16323744/

相关文章:

java - 如果您在 Java 中显式初始化一个 Object 数组,包含 "new Object[]"与不包含它是否不同?

javascript - 手感持久的 CSS

Meteor Handsontable 示例

javascript - Google 通用分析维度和修改跟踪代码

javascript - 如何使用 extjs 在桌面/面板中显示隐藏的小部件?

javascript - Swagger 用户界面 : basic auth for swagger file

javascript - HandsonTable - 修改双击事件

javascript - Node.js Socket.io 错误 : disconnect event is triggered after connect

php - 使用 php 将字符串转换为数组

javascript - 将分割数组的元素设为数字