【问题标题】:Upload jQuery Handsontable input上传 jQuery Handsontable 输入
【发布时间】:2012-06-05 14:44:10
【问题描述】:

将用户在 jQuery Handsontable 中输入的数据上传回服务器以保存到数据库中的最佳方法是什么?

现有的onChange 回调似乎非常冗长,无法使用 AJAX 保存输入数据,尤其是当用户在现有数据行上方插入新数据行时。 在使用 HandsontablejQuery

完成编辑后寻找上传输入数据的功能

这里是full code 使用 jQuery 循环输入数据并以 JSON 格式转储到文本框中,然后提交到服务器。这个过程看起来很难看。寻找更清洁的方式..

$('#btnGo').click(function() {

    var rowList = new Array();
    $("table tr").each(function() {
        var colList = new Array();
        $("td", this).each(function() {
            colList.push($(this).text());
        });
        rowList.push(colList);
    });
    $('#simple').val(JSON.stringify(rowList));
    console.log(rowList);
});​

【问题讨论】:

    标签: javascript jquery spreadsheet handsontable


    【解决方案1】:

    有一个获取整个表格数据数组的内置方法:.handsontable("getData")

    你可以这样使用它:

    $('#btnGo').click(function() {
      var rowList = $("#example9grid").handsontable("getData");
      $('#simple').val(JSON.stringify(rowList));
      console.log(rowList);
    });​
    

    工作示例:http://jsfiddle.net/warpech/bwv2s/20/

    【讨论】:

    • 谢谢,非常有帮助的答案。您的实用插件真的很酷。
    猜你喜欢
    • 2012-06-13
    • 2013-09-16
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 2014-01-22
    • 2011-10-17
    • 2013-08-29
    • 1970-01-01
    相关资源
    最近更新 更多