【发布时间】:2018-06-06 12:50:37
【问题描述】:
我正在使用 handsontable js 插件。我想在 afterChange 钩子中使用 getCellMeta 函数但不起作用。 我在使用 afterChange 钩子函数时,函数正在工作。但在 afterChange 挂钩中不起作用。
var container = document.getElementById('t1'),
options = document.querySelectorAll('.options input'),
table,
hot;
hot = new Handsontable(container, {
autoWrapRow: true,
startRows: 81,
startCols: 206,
autoColumnSize : true,
stretchH: 'all',
afterChange : function(change,source) {
if (source === 'loadData') {
return;
}
var test = this.getCellMeta(change[0],change[1]); // not working, not return "id" meta
console.log(test);
}
});
$.ajax({
url: 'path',
type: 'GET',
dataType: 'json',
success: function (res) {
var data = [], row, pc = 0;
for (var i = 0, ilen = hot.countRows(); i < ilen; i++)
{
row = [];
for (var ii = 0; ii<hot.countCols(); ii++)
{
hot.setCellMeta(i,ii,'id',res[pc].id);
row[ii] = res[pc].price;
if(pc < (res.length-1)) {
pc++;
}
}
data[i] = row;
}
hot.loadData(data);
}
});
var test = this.getCellMeta(0,0); // is working, return "id" meta
console.log(test);
更改后如何获取单元格元数据?
谢谢。
【问题讨论】:
-
我不熟悉这个插件,但是文档只显示了 beforeGetCellMeta 和 afterGetCellMeta ; getCellMeta 是从哪里来的?
-
link@kshikama
标签: javascript jquery hook handsontable