【问题标题】:How to transfer handsontable data to a different JavaScript on the same page?如何在同一页面上将可操作的数据传输到不同的 JavaScript?
【发布时间】:2013-04-25 18:45:02
【问题描述】:

这是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>

【问题讨论】:

  • 您是否尝试将这两个脚本结合起来?
  • @Pizdy 是的,我已经尝试过了。不幸的是,它无法完成,因为这两个部分是两个不同的 JQueries。它们是两个不同的类。
  • 如何打开 jsfiddle?
  • @Kamil 转到链接,它会将您带到handsontable 网站,有一个指向jsfiddle 的按钮
  • 您可以创建一个表单,并使用 PHP 将数据提交到服务器,然后将它们发送回您的脚本,或者您可以使用 URL 中的数据。检查此链接boutell.com/newfaq/creating/scriptpass.html

标签: javascript arrays handsontable


【解决方案1】:

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

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');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多