【问题标题】:jquery grid not filled with JSon datajQuery 网格未填充 JSON 数据
【发布时间】:2012-08-31 22:35:07
【问题描述】:

您好,我无法从加载到网格的 JSON 中获取数据,

这是我的网格代码,它为用户显示股票的股价:

      $(document).ready(function () { 
        //  $("#jQGrid").html("<table id=\"list\"></table><div id=\"page\"></div>");
            jQuery("#jqTable").jqGrid({
                url:jqDataUrl,
                datatype: "json",
                mtype: "POST", 
                height: 250,
             // Specify the column names
                colNames: ["SYMBOL", "LAST", "CHANGE", "%CHANGE","HIGH/LOW"],

                // Configure the columns
                colModel: [
                { name: "SYMBOL", index: "SYMBOL", width: 200, align: "left" },
                { name: "LAST", index: "LAST", width: 200, align: "left" },
                { name: "CHANGE", index: "CHANGE", width: 200, align: "left" },
                { name: "%CHANGE", index: "%CHANGE", width: 200, align: "left"},
                { name: "HIGH/LOW", index: "HIGH/LOW", width: 200, align: "left"}
                ],
                jsonReader : {
                    root: "rows",
                    page: "page",
                    total: "total",
                    records: "records",
                    cell: "cell", 
                    id: "id",
                },
                multiselect: false,
               // paging: true,
              //  rowNum:10,
              //  rowList:[10,20,30],
                pager: $("#jqTablePager"),
                loadonce:true,
                caption: "WatchList"
            }).navGrid('#jqTablePager',{edit:false,add:true,del:true});
        }

});

但是当我尝试运行代码时,我无法将内容放到表格中(但网格加载时没有内容)

我的 json 格式为:

{
total: "1",
 page: "1",
 records: "2",
rows : 
[
{id:"1", cell:["cell11", "cell12", "cell13","cell13","cell13"]},
{id:"2", cell:["cell21", "cell22", "cell23","cell13","cell13"]}
]
}

请帮我解决问题

【问题讨论】:

  • colModel 中的名称用作 HTML 元素 ID,因此它们应遵循这些规则。 %/ 不应该在元素 ID 中使用。不过,我不知道这是否能解决问题。

标签: javascript jquery json jquery-ui


【解决方案1】:

更新

我发现如果你不将repeatitems:true 选项放入 json 阅读器,jqGrid 会假定你使用的是 json 点表示法。当您将其放入 jsonReader 时,您的数据已正确加载。这是工作示例:http://jsfiddle.net/a5e5F/3/


旧版

我玩了很多你的jqgrid代码,看来这个版本的jqGrid有一个bug,导致你的jsonReader不能工作。它直接读取数据,忽略根元素并假设您的数据是格式为 json 对象的数组

{propertyName1:'PropertyValue1', propertyName2:'PropertyValue2', ...} 

你可以在http://jsfiddle.net/a5e5F/2/上看到我的意思

如果将data:rows 替换为data:data(您的数据格式),则不会加载数据。也许您应该尝试将您的 json 数据更改为使用真正的 json 格式(将属性命名为列)?

我一直在尝试很多东西,更改列名以检查@Barmar 评论中的问题,我也认为这是原因。

【讨论】:

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