使用.getSourceData从Handsontable返回nxn数据数组

时间:2017-09-21 17:16:39

标签: javascript html handsontable

我试图从" handsontable"获取源数据对象。使用.getSourceData方法。如果我使用没有可选参数调用方法,控制台会记录一个数组数组,但是当我尝试传递这些参数时,我得到控制台错误。我有一个Fiddle可以输出数组但是如果我取消注释可选参数方法则不起作用。

var data = [
  [0, 0, 0],
  [10, 0.1, 150],
  [20, 0.2, 151]
]

var container1 = document.getElementById('Table'),
  hot1;

var hot1 = new Handsontable(container1, {
  data: data,
  colHeaders: ['Measured Depth', "Inclination", "Azimuth"],
  rowHeaders: true,
  minSpareRows: 0,
  contextMenu: ['row_above', 'row_below', 'remove_row']
});

function countRows() {
  var ht = hot1
  var rowcount = ht.countRows() - ht.countEmptyRows();
  return rowcount;
}

console.log(countRows())

function submitForm() {
  var htContents = hot1.getSourceData() //getSourceData(1,1,countRows(),3)
  console.log(htContents);
}

$("#get_data").click(submitForm);

1 个答案:

答案 0 :(得分:0)

我从来没有使用该功能,但是使用countRows()限制输出返回空白的工作是什么

for (i = 0; i < countRows(); i++) {
  md.push(htContents[i][0]);
  inc.push(htContents[i][1]);
  azi.push(htContents[i][2]);
}