【发布时间】:2015-07-02 08:56:15
【问题描述】:
我有handsontable,我想将handsontable 单元上的数据输入服务器端。我试图在代码下面运行,但数据不是预期的格式。我期望以纯 json 格式获取数据作为列标题作为键。
HTML代码
<div class="handsontable" id="example"></div>
<input type="button" name="submit" value="submit" onclick="submitForm()" />
创建handsontable的代码
$(document).ready(function () {
$('#example').handsontable({
startRows: 2,
startCols: 2,
rowHeaders: true,
colHeaders: true,
contextMenu: true,
});
});
从handsontable中提取信息的代码
function submitForm(){
var $container = $('#example');
var htContents = JSON.stringify($container.handsontable('getData'));
alert(htContents);
}
目前handsontable 有2 行2 列。现在,如果我按下单元格值 (1,1)=11,(1,2)=12,(2,1)=21 和 (2,2)=22 的按钮,我得到的结果是在警报窗口中
[["11","12"],["21","22"]]
但我期待的结果是
[{"A":"11","B":"12"},{"A":"21","B":"22"}]
其中 A 和 B 是列标题。
【问题讨论】:
标签: javascript jquery json handsontable