Handsontable - getSelected不工作

use*_*621 3 javascript excel getselection handsontable

我正在使用handsontable创建一些类似excel的电子表格,我需要检索用户选择的数据以使用gRaphael创建图表.但是当我尝试使用此代码甚至警告数据选择参数时:

var ht = $('#dataTable0').data('handsontable');
var sel = ht.getSelected();
alert(sel[0]);
Run Code Online (Sandbox Code Playgroud)

我在警报窗口中写了"未定义".有人能告诉我如何修复此代码吗?

Pos*_*ing 16

您的代码已过时,这可能是它无法按预期工作的原因.如果您使用的是最新版本0.9.7,建议使用的方法是:

$('div#example1').handsontable(options);

//get the instance using jQuery wrapper
var ht = $('#example1').handsontable('getInstance');

//Return index of the currently selected cells as an array [startRow, startCol, endRow, endCol]
var sel = ht.getSelected();

//'alert' the index of the starting row of the selection
alert(sel[0]);
Run Code Online (Sandbox Code Playgroud)

如果您使用的是旧版本,我建议您下载最新版本.

编辑:

正如@polras所建议的那样,您还可以添加:

outsideClickDeselects: false 
Run Code Online (Sandbox Code Playgroud)

以handsonetable选项

  • 这里的情况相同.我添加了**outsideClickDeselects:false**到handsonetable选项.把这个片段作为进一步的参考 (10认同)
  • 我刚刚意识到我的代码实际上工作得很好,就是当我点击链接时调用了这个代码(函数),这导致表中的选择被"取消选择",这导致获得"未定义"警告消息.对不起,我什么都没打扰你.的xD (2认同)