Kendo UI Grid Json数据未加载

时间:2013-05-25 16:43:42

标签: java javascript kendo-ui kendo-grid amazon-dynamodb

我在kendo ui网格中加载json数据时遇到问题。我能够根据response1在数据网格中加载数据,因为db-table有多个记录,这些值在网格中完美加载。如果db只包含一个未加载的记录。在kendo中,我提到了多个记录的模式模型。我根据响应动态加载。

在我的webservice中注意:Response2只是json对象

响应1包含对象数组。

如何加载而不提及kendo ui网格中的架构?

如何在kendo ui网格中实现动态架构?

我的回复样本是:

响应1:

{"dataFile":[{"dataFileKey":"LLf38e8826-e86c-4b8e-ba76-5e9a036e9481","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"62"},{"dataFileKey":"LLf6ec3702-3714-4723-afdd-dd43cc97ed9e","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"56"},{"dataFileKey":"LL78df7a13-8de3-43e8-8976-9fd7513267d3","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"65"},{"dataFileKey":"LLb1efa732-1110-412d-b3b6-1b774397f5fe","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"55"},{"dataFileKey":"LLc87dfb0b-8f3c-4214-9e93-c879ec291fcf","dataFileName":"sample_results.xls","experimentID":"47","id":"52"},{"dataFileKey":"LLe78010d1-a6d4-4666-83d3-e10883cad64e","dataFileName":"ANdroid.rtf","experimentID":"47","id":"80"},{"dataFileKey":"LLdd323ac7-f11a-4211-acc7-b6f24e4c9b97","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"66"},{"dataFileKey":"LL322664c0-6834-4410-b09e-66b215a5a39c","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"63"},{"dataFileKey":"LL18eea7cd-fcf7-4e72-ab83-fd0eaaaf28dc","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"59"},{"dataFileKey":"LL8813caea-2bd8-406c-813d-820ad89a36b2","dataFileName":"UI .txt","experimentID":"47","id":"71"},{"dataFileKey":"LL0a58e6b5-44c5-44be-808c-a36edfc52157","dataFileName":"dynamodb-dg.pdf","experimentID":"47","id":"61"},{"dataFileKey":"LL84bf6b13-43f6-4b98-af33-3610fc04f30d","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"51"},{"dataFileKey":"LLa25825ce-0a87-403b-94fb-f6165eb9e8d5","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"64"},{"dataFileKey":"LL6647ad1e-8d8c-4891-b64a-9eced150b377","dataFileName":"sample_results.xls","experimentID":"47","id":"68"},{"dataFileKey":"LLf14ba2c7-7898-4392-92d6-b47ca08f9d63","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"67"},{"dataFileKey":"LL1a99399e-c266-4c5b-ba39-b1fdc5e073c5","dataFileName":"10.10-si.dynamicrange-1k.2.EDS","experimentID":"47","id":"57"},{"dataFileKey":"LLb2a68fcd-2e74-4257-8c8b-93e3463e7681","dataFileName":"dynamodb-dg.pdf","experimentID":"47","id":"60"}]}

回应2:

{"dataFile":{"dataFileKey":"LL25586c00-d95f-41c8-ad49-370dfd29b68a","dataFileName":"ANdroid.rtf","experimentID":"30","id":"78"}}

我到目前为止尝试过:

$(document).ready(function () {
    $("#grid").kendoGrid({
        dataSource : {
            type     : "json",
            transport: {
                read: "/lexaserver/rest/datafiles/all"
            },
            schema   : {
                data: "dataFile"
            },
            pageSize : 10
        },
        height     : 200,
        sortable   : true,
        reorderable: true,
        resizable  : true,
        pageable   : true,
        columns    : [
            {
                field: "id",
                title: "Data File ID",
                width: 110
            },
            {
                field: "dataFileName",
                title: "File Name",
                width: 110

            },
            {
                //  field: "dataFileKey",
                title   : "File Key",
                width   : 110,
                template: "<a class='download-files' fname=${dataFileName} key='${dataFileKey}' href=''>download file</a>",
            }
            //  { command: { text: "Download", click: showDetails }, title: " ", width: 30 }
        ]
    });
});

1 个答案:

答案 0 :(得分:0)

问题是您的服务以不同的格式返回数据,具体取决于您是否有一个或多个记录。 Kendo UI期望它始终具有相同的功能。

选项:

  1. 修改您的服务,以便始终返回相同的格式。
  2. 实现一个函数,在接收数据时检查格式并将其转换为普通格式。
  3. 方法2的示例,将schema中的DataSource定义更改为:

    schema   : {
        parse: function (d) {
            if (d.dataFile) {
                return d.dataFile;
            } else {
                return [ d ];
            }
        }
    },
    

    我检查我收到的数据是否有d.dataFile并返回,否则返回一个包含所收到数据内容的数组。