如何在kendo.data.Datasource上获得单个结果

Quo*_*yen 2 kendo-ui kendo-mobile kendo-mvvm

我有这样的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
    }
Run Code Online (Sandbox Code Playgroud)

我试图通过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);
    });
Run Code Online (Sandbox Code Playgroud)

但不确定为什么它总是抛出错误:

Uncaught TypeError: Object [object global] has no method 'slice' 
Run Code Online (Sandbox Code Playgroud)

请帮我.谢谢

Sub*_*ata 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}]
Run Code Online (Sandbox Code Playgroud)

然后它会正常工作.NB它是数组格式.

要么

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

schema: {
  data: function(server-response) {
    return [server-response];
  }
}
Run Code Online (Sandbox Code Playgroud)

剑道团队应该把更多的时间放在好的文档上.