Kendo网格没有填充json数据

时间:2013-07-18 14:22:41

标签: jquery kendo-ui kendo-grid

以下是我创建Kendo网格的方法

var grid = $("#grid").kendoGrid({
    autobind:true,
    dataSource: {
        transport: {
            read: {
                url: "getFacetTree?action=datagrid",
                dataType: "json"
            }
        },

        schema: {
            model: {
                fields: {
                    Details: { type: "number" },
                    Date: { type: "string" },
                    AuthorSender: { type: "string" },
                    Recipients: { type: "string" },
                    SubjectFilename: { type: "string" },
                    Action: { type: "string" }
                }
            }
        },
        pageSize: 10,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true
    },
    height: 250,
    sortable: {
        mode: "multiple",
        allowUnsort: true
    },
    filterable: {
        extra: false,
        operators: {
            string: {
                startswith: "Starts with",
                eq: "Is equal to",
                neq: "Is not equal to"
            }
        }
    },
    columnMenu: true,
    resizable: true,
    pageable: {
        input: true,
        numeric: false,
        pageSizes: true,
        messages: {
            display: "{2} - Documents found, displaying {0} to {1}"
        }
    },
    editable: true,
    columns: [
        {
            field: "",
        title: "<input id='headerCheckbox' onclick='selectRows(this)' type='checkbox' name='selected' />",
        width: 21,
        template: "<input class='rowCheckbox' type='checkbox' name='selected' />"
        },
        {
            field: "Details",
            title: "Details",
            width: 50
        },
        {
            field: "Date",
            title: "Date",
            width: 100
        },
        {
            field: "AuthorSender",
            title: "Author/Sender",
            width: 150
        },
        {
            field: "Recipients",
            title: "Recipients",
            width: 150
            /*filterable: false*/
        },
        {
            field: "SubjectFilename",
            title: "Subject/Filename",
            width: 150
        },
        {
            field: "Action",
            title: "Action",
            width: 60
        }
    ] 
});

我从数据源获得的响应是​​ -

[{ Details : 1,  Date : "12-06-2000",    AuthorSender : "sd",    Recipients : "we",    SubjectFilename : "abc abc.url",    Action : "view"},{ Details : 1,  Date : "12-06-2000",    AuthorSender : "sd",    Recipients : "we",    SubjectFilename : "abc abc.url",    Action : "view"}]

但是网格中没有更新响应。我有什么问题吗?

Firebug中的分析(网络标签)显示它有5个标签 - Params,Headers,Response,Cache,XML,Cookies。
在XML选项卡下我得到了这个(也许这是错误的地方) -

XML Parsing Error: syntax error Location: moz-nullprincipal:{c48e084c-70a2-4462-8411-0a950e5325d9} Line Number 1, Column 1:

[{ Details : 1,  Date : "12-06-2000",    AuthorSender : "sd",    Recipients : "w...

1 个答案:

答案 0 :(得分:0)

有两个错误:
1. json响应中的 key 字段应该有引号。
2.在架构下,我必须将string响应解析为json,如下所示

schema: {
    model: {
        fields: {
            Details: { type: "String" },
            ...
            Action: { type: "String" }
        }
    },
    parse: function(response) {
        return $.parseJSON(response);
    }
},