上传jQuery Handsontable输入 [英] Upload jQuery Handsontable input

查看:82
本文介绍了上传jQuery Handsontable输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the best way to upload data entered by user in jQuery Handsontable back to Server to be saved into database?

使用AJAX保存输入数据时,现有的 onChange 回调似乎非常冗长,尤其是当用户插入新数据行时以上现有的。
寻找使用 Handsontable jQuery 完成编辑后上传输入数据的功能

The existing onChange callback seems to be very verbose to save input data using AJAX especially if user insert new data row above existing one. Looking for functionality to upload input data after complete the editing using Handsontable or jQuery

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

Here is the full code using jQuery to loop the input data and dump into text box in JSON format then submit to server. This process look ugly. looking for a cleaner way..

$('#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);
});​


推荐答案

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

There is a build in method for getting the whole array of table data: .handsontable("getData")

您可以像这样使用它:

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

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

这篇关于上传jQuery Handsontable输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆