【问题标题】:jqGrid - error when JSON has no 'rows' data with jsonReaderjqGrid - 当 JSON 没有带有 jsonReader 的“行”数据时出错
【发布时间】:2013-05-22 11:44:08
【问题描述】:

将 jqGrid 与 Fusion Tables 一起使用,如果 JSON 返回结果,它工作正常,但如果没有结果,则因为 obj.rows 不存在,尝试检查长度时分页符。有没有办法优雅地处理这个问题?

jsonReader: {
            cell: "",
            page: function (obj) { return 1; },
            total: function (obj) { return 1; },
            records: function (obj) { return obj.rows.length; } 

        },

未捕获的类型错误:无法读取未定义的属性“长度”

和 JSON:

// API callback
jQuery16405104181477800012_1369220882365({
 "kind": "fusiontables#sqlresponse",
 "columns": [
  "id",
  "latitude",
  "longitude",
  "name",
  "address_line_1",
  "address_line_2",
  "address_line_3",
  "postcode"
 ]
}
);

以下是带有行的结果示例:

jQuery1640010438381228595972_1369222778703({
 "kind": "fusiontables#sqlresponse",
 "columns": [
  "id",
  "latitude",
  "longitude",
  "name",
  "address_line_1",
  "address_line_2",
  "address_line_3",
  "postcode"
 ],
 "rows": [
  [
   "1132584",
   50.55307,
   "-4.19639",
   "The Road",
   "ROAD",
   "Town",
   "CITY",
   "POSTCODE"
  ],

【问题讨论】:

    标签: jquery json jqgrid


    【解决方案1】:

    我认为您可以将records函数修改为

    records: function (obj) {
        return obj.rows != null ? return obj.rows.length : 0;
    } 
    

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题,

      我创建了一个 div 来显示 jqgrid,但您必须创建一个表格。

      我做到了,它奏效了! :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多