Kendo UI - Datagrid,如何添加额外的参数来请求?

时间:2014-06-11 10:55:50

标签: post datagrid kendo-ui

我有可编辑的数据网格。我想将读传输更改为POST并向json请求添加一些其他数据(例如access_token)。

下面的示例产生GET请求而不是POST而没有其他数据。

问题是:我该怎么做?

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 个答案:

答案 0 :(得分:1)

有几个选择:

选项1.使用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
}

选项2.将它们添加到transport.paremeterMap函数

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)};
}