Kendo UI - Datagrid, how to add additional params to request?

♀尐吖头ヾ 提交于 2019-12-11 13:34:15

问题


I have editable datagrid. I would like to change read transport to POST and add some additional data to json request (for example access_token).

Example below produce GET request instead of the POST and without additional data.

Question is: How can i do that?

dataSource = new kendo.data.DataSource({
              transport: {
                  read:  {
                      type: "POST",
                      url: crudServiceBaseUrl + "/Products",
                      contentType: "application/json; charset=utf-8",
                      dataType: "jsonp",
                      data: { "my_param": 1}
                  },
                  update: {
                      type: "PUT",
                      url: crudServiceBaseUrl + "/Products/Update",
                      dataType: "jsonp",
                      data: { "my_param": 1}
                  },
                  destroy: {
                      type: "DELETE",
                      url: crudServiceBaseUrl + "/Products/Destroy",
                      dataType: "jsonp",
                      data: { "my_param": 1}
                  },
                  create: {
                      url: crudServiceBaseUrl + "/Products/Create",
                      dataType: "json",
                      type: "PUT",
                      data: { "my_param": 1}
                  },
                  parameterMap: function(options, operation) {
                          console.log(options);
                          console.log(operation);
                          return {data: kendo.stringify(options.models)};
                  }

              },

回答1:


Several options:

Option 1. Use transport.read.data

read:  {
    type: "POST",
    url: crudServiceBaseUrl + "/Products",
    contentType: "application/json; charset=utf-8",
    dataType: "jsonp",
    data: { "my_param": 1, access_token : "my_token" }  // send parameter "access_token" with value "my_token" with the `read` request
}

Option 2. Add them into transport.paremeterMap function

parameterMap: function(options, operation) {
    console.log(options);
    console.log(operation);
    if (operation.type === "read") {
        // send parameter "access_token" with value "my_token" with the `read` request
        return {
            data: kendo.stringify(options.models),
            access_token: "my_token"
        };
    } else
        return {data: kendo.stringify(options.models)};
}


来源:https://stackoverflow.com/questions/24161159/kendo-ui-datagrid-how-to-add-additional-params-to-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!