2

我有这样的 Odata 结果

        {"odata.metadata":"https://localhost/DocTalkMobileWebApiOData/odata/$metadata#MasterPatient/@Element","PatUniqueId":"39e713db-6a0e-4e59-bf7b-033f4fc47ad5",  "PatID":null,
"pat_lname":"White","pat_fname":"Peter","pat_mi":"     ","pat_ssn":"270787655","pat_dob":"08/07/1973","pat_sex":"M","pat_status":null,"priInsID":2,"secInsID":1,"PCPID":1,"InternalDrID":1,"EXPID":1,"EXPDate":"","pat_phone":null,"isNew":true,"imported":true,"byWhom":"dt","lastUpdate":"2011-03-30T09:41:57.36","changeStamp":"AAAAAAAAIUE=","address":"","city":"","state":"","zip":"","currentMcp":"","currentVisitCount":-2,"otherId":"543674","pcpName":null,"hasChanges":true,"ProgramSource":null,"mrnID":"","createdBy":null,"createdDate":"2007-10-26T10:16:15","expLocation":null,"ethnicId":1,"prefLanguageId":1,"raceId":1
    }

我试图通过 kendo.ui.datasource 得到这个结果:

 newPatient = new kendo.data.DataSource({
        type: 'odata', // <-- Include OData style params on query string.
        transport: {
            read: {
                url: url + '/MasterPatient(guid\'00000000-0000-0000-0000-000000000000\')', // <-- Get data from here
                dataType: "json" // <-- The default was "jsonp"
            },

            parameterMap: function (options, type) {
                var paramMap = kendo.data.transports.odata.parameterMap(options);

                delete paramMap.$inlinecount; // <-- remove inlinecount parameter.
                delete paramMap.$format; // <-- remove format parameter.

                return paramMap;
            }
        },
        schema: {
            data: function (data) {                 
                return data;
            },
            total: function (data) {                 
             return  data['odata.count']
            },
        }
    });
    newPatient.fetch(function () {
        kendo.bind($('#newPatientTab'), newPatient);
    });

但不知道为什么它总是抛出错误:

Uncaught TypeError: Object [object global] has no method 'slice' 

请帮我。谢谢

4

2 回答 2

6

在 Kendo UI 中,DataSource 仅适用于数组。如果您可以更改服务器响应以发送类似这样的内容

[{"odata.metadata":"https://localhost/DocTalkMobileWebApiOData/odata/$metadata#MasterPatient/@Element","PatUniqueId":"39e713db-6a0e-4e59-bf7b-033f4fc47ad5","PatID":null,"pat_lname":"White","pat_fname":"Peter","pat_mi":"     ","pat_ssn":"270787655","pat_dob":"08/07/1973","pat_sex":"M","pat_status":null,"priInsID":2,"secInsID":1,"PCPID":1,"InternalDrID":1,"EXPID":1,"EXPDate":"","pat_phone":null,"isNew":true,"imported":true,"byWhom":"dt","lastUpdate":"2011-03-30T09:41:57.36","changeStamp":"AAAAAAAAIUE=","address":"","city":"","state":"","zip":"","currentMcp":"","currentVisitCount":-2,"otherId":"543674","pcpName":null,"hasChanges":true,"ProgramSource":null,"mrnID":"","createdBy":null,"createdDate":"2007-10-26T10:16:15","expLocation":null,"ethnicId":1,"prefLanguageId":1,"raceId":1}]

那么它会正常工作。注意它是数组格式。

或者

您可以将单个对象包装到客户端的数组中,在模式的数据函数内部。

schema: {
  data: function(server-response) {
    return [server-response];
  }
}

Kendo 团队应该把更多的时间放在好的文档上。

于 2013-10-25T05:38:17.083 回答
3

这意味着您没有使用支持的 odata 源。在这种情况下,如果您的后端不正确支持 odata,您需要在这里考虑是否真的需要来自客户端的 kendo odata 源。

请参阅来自 odata url 的响应,http: //services.odata.org/Northwind/Northwind.svc/ ?$format=json

value它应该在字段中返回一个对象数组。如果您无法更改支持的内容,您可以做的是在 Schema.data 函数中格式化数据

schema: {
        data: function (data) {                 
            return [data];
        },
于 2013-10-25T05:40:03.980 回答