How dataSource.transport work for data format?

1 Answer 13 Views
Data Source
sojin
Top achievements
Rank 1
sojin asked on 27 Jan 2022, 12:13 AM | edited on 27 Jan 2022, 12:22 AM

 

Hi, I want to send data for json format. 

 

This is my data format.

data = {models: Array(1)}, type = "update....

I want to send data like this.


data = {foo: 'bar', locale: 'en', name: 'test', description: '1', ...}

 

This data is same as {models:Array(1)} 's array.

 

My code is here. I used parameterMap to data format for change.

                parameterMap: function (data, type) {
                     if (type === "update") {
                        debugger;
                        return kendo.stringify(data.models[0]);
                    }
                    return kendo.stringify(data);
                }


But when sending data, DataSource.transport.update send another data like this.

 


        var users = new kendo.data.DataSource({
            transport: {
                update: {
                    contentType: contentType,
                    url: function (options) {

                        return base_api_url_manage_users + "info/" + options.models[0].userId ;
                    },
                    type: "PUT",
                },


They send this format.

data = {models: Array(1)}, type = "update....

 

I want to send data form as Objcet, not as Object in Array. How can I change this data format???

Please help me.

 

Thank you.

1 Answer, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 31 Jan 2022, 10:28 AM

Hi,

You can do that by creating a custom update function that handles the AJAX request and passing the data parameter as per to your requirements: 

        update: function(options) {
          $.ajax({
            url: "https://url.to.endpoint",
            // send the updated data items as the "models" service parameter encoded in JSON
            data: {
              models: options.data.models[0] // or kendo.stringify(options.data.models[0])
            },
            success: function(result) {
              // notify the data source that the request succeeded
              options.success(result);
            },
            error: function(result) {
              // notify the data source that the request failed
              options.error(result);
            }
          });
        }
      },

This is shown as an option in the second example of the transport.update option.

Regards,
Ianko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Data Source
Asked by
sojin
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Share this question
or