0

Using jqGrid with Fusion Tables, if the JSON returns with results it works fine, but if there are no results then because obj.rows doesn't exist, the page breaks when trying to check the length. Is there a way to handle this gracefully?

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

        },

Uncaught TypeError: Cannot read property 'length' of undefined

and the JSON:

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

and below is an example of a result with rows:

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"
  ],
4

2 回答 2

0

我认为您可以将records功能修改为

records: function (obj) {
    return obj.rows != null ? return obj.rows.length : 0;
} 
于 2013-05-22T17:43:30.047 回答
0

我遇到了完全相同的问题,

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

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

于 2013-10-14T17:19:00.243 回答