问题
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