Kendo UI - Datagrid,如何添加额外的参数来请求? [英] Kendo UI - Datagrid, how to add additional params to request?
本文介绍了Kendo UI - Datagrid,如何添加额外的参数来请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的示例生成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}
},
更新: {
type:PUT,
url:crudServiceBaseUrl +/ Products / Update,
dataType:jsonp,
data:{my_param:1}
},
des troy:{
type:DELETE,
url:crudServiceBaseUrl +/ Products / Destroy,
dataType:jsonp,
data:{my_param
},
创建:{
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.使用 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} //发送参数access_token,值为my_token `request
}
选项2.将它们添加到 transport.paremeterMap
功能
parameterMap:function(options,operation){
console.log(options);
console.log(operation);
if(operation.type ===read){
//发送参数access_token,带有read请求的值为my_token
return {
data :kendo.stringify(options.models),
access_token:my_token
};
} else
return {data:kendo.stringify(options.models)};
}
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)};
}
},
解决方案
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)};
}
这篇关于Kendo UI - Datagrid,如何添加额外的参数来请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文