【问题标题】:Jqgrid not binding dataJqgrid不绑定数据
【发布时间】:2015-01-02 10:00:56
【问题描述】:

我正在从 WebService 获得 Json 响应,如下所示

Json 完美返回数据。数据看起来像

{"d":"[{\"ID\":2,\"Code\":\"mycode\",\"Name\":\"Myname\",\"PassWord\":\ "A\",\"ClientLevel\":0,\"DeptNo\":\"\",\"DeptName\":\"\"},{\"ID\":3,\"Code\" :\"mycode\",\"Name\":\"ly1\",\"PassWord\":\"mypassword\", .......但不绑定我的jqgrid。

我有以下 Jqgrid 代码

jQuery("#list2").jqGrid({
                mtype: 'POST',
                url: "myservice.asmx/GetQueryInfo",                  

                serializeGridData: function (postData) {
                    return JSON.stringify({
                        TableNames: TableName,
                        ColumnList: ColumnNames
                    });
                },

                ajaxGridOptions: { contentType: "application/json; charset=utf-8" },
               jsonReader: {
                        repeatitems: false,
                        root: 'd',                           
                        page: function (obj) { return 1; },
                        total: function (obj) { return 1; },
                        records: function (obj) { return obj.toString().length; }
                    },
                datatype: 'json',
                colNames: ['ID', 'Code', 'Name', 'PassWord', 'ClientLevel', 'DeptNo', 'DeptName'],
                colModel: [
                    { name: "ID", width: 55 },
                    { name: "Code", width: 90 },
                    { name: "Name", width: 100 },
                    { name: "PassWord",  width: 80 },
                    { name: "ClientLevel",  width: 80 },
                    { name: "DeptNo",  width: 80 },
                    { name: "DeptName",  width: 150 }
                ],
                autoencode: true,
                gridview: true,
                rowNum: 10,
                loadonce: true,
                rowList: [10, 20, 30],
                pager: '#pager2',
                sortname: 'ID',
                viewrecords: true,
                sortorder: "ID",
                caption: "JSON Example",
                loadError: function (jqXHR, textStatus, errorThrown) {
                    alert('HTTP status code: ' + jqXHR.status + '\n' +
                          'textStatus: ' + textStatus + '\n' +
                          'errorThrown: ' + errorThrown);
                    alert('HTTP message body (jqXHR.responseText): ' + '\n' + jqXHR.responseText);
                }
            });
            jQuery("#list2").jqGrid('navGrid', '#pager2', { edit: false, add: false, del: false });

【问题讨论】:

    标签: c# asp.net json web-services jqgrid


    【解决方案1】:

    我仍然认为您在服务器端使用旧代码(WebMethod 返回字符串而不是对象),因为 d 属性的值是字符串。您可以使用jsonReader 中的root 作为the answer 中定义的函数。在这种情况下,它也适用于您的情况。所以你可以使用

    jsonReader: {
        repeatitems: false,
        root: function (obj) {
            return typeof obj.d === "string" ? $.parseJSON(obj.d) : obj.d;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-21
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 2017-01-14
      相关资源
      最近更新 更多