我有一个 igGrid,它显示数据库表中的字段,其中一些条目为 NULL。
$.ig.loader(function () {
$("#igGrid").igGrid({
autoGenerateColumns: false,
dataSource: "/myapp/SrvUser?parm=all",
columns: [
{ headerText: "ID", key: "id", dataType: "string" },
{ headerText: "Name", key: "name", dataType: "string" },
{ headerText: "Type", key: "type", dataType: "string" }
],
features: [{
blah ...
}]
});
servlet 返回如下数据:
userList = (List<BeanUser>) DButil.getUserList(parm);
String json = gson.toJson(userList);
response.setContentType("application/json");
response.getWriter().write(json);
如果任何列为 NULL 并出现此错误,则失败:
Error: The remote request to fetch data has failed: (parsererror) There was an error parsing the JSON data and applying the defined data schema:
The input data doesn't match the schema, the following field couldn't be mapped: type
棘手的部分是,在 Eclipse Debug 中,我设置了一个断点,在发送之前在 servlet 中捕获了 JSON 数据,如果我在网格定义中使用这些确切的数据,它就可以工作!
var data = [{"id":"ID1","name":"Name1","type":"regular"},
{"id":"ID2","name":"Name2"}
];
$.ig.loader(function () {
. . .
dataSource: data,
所以它不是网格定义,我还有其他包含 NULL 值的 igGrid(在网格中正确显示为空白),但这些网格不使用 servlet 作为数据源。他们使用这个:
dataSource: $.parseJSON('<%=request.getAttribute("jsonData")%>'),
我是否必须更改我的 servlet 中的某些内容?还是网格定义?是否有另一种定义数据源以从 servlet 获取数据的方法?