我是Handsontable的新人。
我想调用Handsontable的方法,例如getData或selectCell。我已经尝试了documentation所说的内容,但它不起作用。
以下是我的JavaScript(jQuery)代码:
$(document).ready(function () {
var test;
$.ajax({
type: 'POST',
url: 'accounting/ajax/ajaxLoadForViewAccount.php',
datatype: 'script',
data: {
tbname:tbname
},
success: function (response) {
test = JSON.parse(response);
var data = new Array();
var headerName = new Array();
var i=0;
for(i=0;i<test.room_num.length;i++){
var obj = {room_num:test.room_num[i],rental_fee:test.rental_fee[i]};
data.push(obj);
headerName[i] = test.room_num[i];
}
var container = document.getElementById('example');
var hot;
hot = new Handsontable(container, {
data: data,
colWidths: [80, 80],
rowHeaders: headerName,
colHeaders: ['room_num','rental_fee']
});
},
error: function () {
alert('error');
}
});
$('#submit').click(function () {
$('#example').append("<p>Testtttttttttttttttttttttttttttttttttttttt</p>");
$('#example').handsontable('setDataAtCell',1,1,'10000');
alert('test');
});
});
根据我的代码,点击提交按钮后,example
div附加了&#34; Testtttttttttttttttttttt&#34;这意味着$('example')
选择器应该可以正常工作。此外,还会显示'test'
警报。但是,方法setDataAtCell
无效。
答案 0 :(得分:1)
考虑始终使用Serialization
实例变量来访问实例。在你的情况下:
hot