【问题标题】:Unable to pass data from javascript to json无法将数据从 javascript 传递到 json
【发布时间】:2015-07-01 20:41:06
【问题描述】:

我想将数据从桌上的手传递到 servlet 。我尝试了一种方法,当 iItry 传递给 servlet 时,我能够获取数据我无法从 request.getParameter("forecastdata"); 获取数据,该数据为空。请告诉我的代码中的错误是什么 ArrayToJson

@WebServlet("/arrayToJson/*")
public class ArrayToJson extends HttpServlet {
    @Override
    protected void doPost(final HttpServletRequest request,
            final HttpServletResponse response) throws ServletException,
            IOException {
        StringBuffer jb = new StringBuffer();
        String line = null;
        request.getParameter("forecastdata");
        ;
    }
}

JavaScript

$("#divButtons").find(".btnSubmit").click(function () {
    console.log($container.data('handsontable').getData());
   var forecast=$container.data('handsontable').getData()
    $.ajax({
        url: "/Pj_IFRS_P5/arrayToJson",
        data: {
            forecastdata: forecast
        }, //returns all cells' data
        dataType: 'json',
        type: 'POST',
        success: function (data) {
            if (data.result === 'ok') {
                console.log('Data saved');
            } else {
                console.log('Save error');
            }
        },
        error: function () {
            console.log('Save error. POST method is not allowed on GitHub Pages. Run this example on your  own server to see the success message.');
        }
    });
});

$("#handsontable").handsontable(config);


});

【问题讨论】:

  • 它为这一行打印了什么 "console.log($container.data('handsontable').getData());"
  • 打印数据值
  • 我现在的问题是如何有条件地禁用handsontable中的行

标签: javascript json servlets handsontable


【解决方案1】:

由于您使用的是 jquery,因此您可以使用过滤器检查您的条件并完全禁用该行。有很多例子,甚至在 stackoverflow 中。

一个例子和小提琴是HERE

如果这是你现在的情况,这可能会回答它!

【讨论】:

  • 我通过给出这段代码实现了它 if(this.instance.getDataAtCell(row, 0) != '--Forecast'){ cellProperties.readOnly = true; }
  • 我想知道如何用货币限制handsontable中的字段
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-03
相关资源
最近更新 更多