Вопрос

I have an Odata result like this

        {"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
    }

and i tried to get this result via 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);
    });

But not sure why it always throw error :

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

Please help me. Thanks

Это было полезно?

Решение

In Kendo UI, DataSource works only with arrays. If you can change the server response to send something like this

[{"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}]

then it will work fine. N.B. It's in array format.

OR

You can wrap the single object into array on the client side, inside data function of the schema.

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

The Kendo team should put more time on good Documentation.

Другие советы

That means you are not using an odata source from the backed. You need to think about here do you really need a kendo odata source from the client in this case if your back-end not supported odata correcly.

See this response from odata url, http://services.odata.org/Northwind/Northwind.svc/?$format=json

It should return an array of object in the value field. If you can't change the backed what you can do is to format the data in the Schema.data function

schema: {
        data: function (data) {                 
            return [data];
        },
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top