【发布时间】: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"
],
【问题讨论】: