jQuery 剑道数据源参数图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18695302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Kendo dataSource Parameter Map
提问by tishantha
I am new to kendo. I'm having a problem with model binding. When i debug with firebug, it shows options.models is undefined. Because of that reason the "if" condition in parrameterMap is always false and grid doesn't populate the data. But when i remove the parrameterMap part, it works.I think, it's very helpful if somebody can explain about the parameter mapin kendo dataSource. Thank you.
我是剑道新手。我遇到了模型绑定问题。当我用 firebug 调试时,它显示options.models 是undefined。因此,参数映射中的“if”条件始终为 false,并且网格不会填充数据。 但是当我删除参数映射部分时,它可以工作。我认为,如果有人可以解释剑道数据源中的参数映射,那将非常有帮助。谢谢你。
function GetDataSource() {
var PrjKy = $("#cmbPrjNm").val();
if (PrjKy == "") { PrjKy = 1; }
var PrcsDetKy = 1;
if (PrcsDetKy == "") { PrcsDetKy = 1; }
var PrcsTypKy = $("#toDotype").val();
if (PrcsTypKy == "") { PrcsTypKy = 1; }
var AprPrtyKy = $("#cmbPiority").val();
if (AprPrtyKy == "") { AprPrtyKy = 1; }
var AprStsKy = $("#status").val();
if (AprStsKy == "") { AprStsKy = 1; }
var OrginAdrKy = 1;
if (OrginAdrKy == "") { OrginAdrKy = 1; }
var AprUsrKy = 1;
if (AprUsrKy == "") { AprUsrKy = 1; }
var NxtActByAdrKy = $("#cmbEmployee").val();
if (NxtActByAdrKy == "") { NxtActByAdrKy = 1; }
var FrmNxtActEntDt = $("#FrmNextActEnt").val();
var ToNxtActEntDt = $("#ToNextActEnt").val();
var FrmNxtActDt = $("#rcdDt").val();
var ToNxtActDt = $("#toDt").val();
var FrmInsertDt = $("#insrtDt").val();
var ToInsertDt = $("#InsrtToDt").val();
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Content("~/User/GetAllToDo")',
data: {
'PrjKy': PrjKy,
'PrcsDetKy': PrcsDetKy,
'PrcsTypKy': PrcsTypKy,
'AprPrtyKy': AprPrtyKy,
'AprStsKy': AprStsKy,
'OrginAdrKy': OrginAdrKy,
'AprUsrKy': AprUsrKy,
'NxtActByAdrKy': NxtActByAdrKy,
'FrmNxtActEntDt': FrmNxtActEntDt,
'ToNxtActEntDt': ToNxtActEntDt,
'FrmNxtActDt': FrmNxtActDt, //changed on 2013-8-30
'ToNxtActDt': ToNxtActDt, //changed on 2013-8-30
'FrmInsertDt': FrmInsertDt, //changed on 2013-8-30
'ToInsertDt': ToInsertDt//changed on 2013-8-30
},
dataType: "json"
},
update: {
url: "~/Home/UpdateToDo",
contentType: 'application/json; charset=utf-8',
dataType: "json",
type: "POST"
},
create: {
url: '@Url.Content("~/Home/UpdateToDo")',
contentType: 'application/json; charset=utf-8',
dataType: "json",
type: "POST"
},
destroy: {
url: '@Url.Content("~/User/DeleteToDo")',
contentType: 'application/json; charset=utf-8',
dataType: "json",
type: "POST"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return JSON.stringify({ models: options });
}
}
},
pageSize: 10
, schema:
{
model:
{
id: "PrcsDetKy", //Primary key to uniquely identify the row.
fields: //Relavent fields of the grid should be bind with following model items
{
ID: { editable: false, nullable: false },
NxtActEntDt: { editable: true, nullable: false, validation: { required: true} },
AprPrty: { editable: true, nullable: false, validation: { required: true} },
AprUsr: { editable: true, nullable: true },
AprSts: { editable: true, nullable: true },
AprStsKy: { editable: true, nullable: true },
AprPrtyKy: { editable: true, nullable: true },
AprUsrKy: { editable: true, nullable: true },
AprResnKy: { editable: true, nullable: true },
PrjId: { editable: true, nullable: true },
TaskId: { editable: true, nullable: true },
TaskNm: { editable: true, nullable: false }, //validation: { required: true}
PrcsDetKy: { editable: false, nullable: false },
TaskTyp: { editable: true, nullable: false },
PrcsTypKy: { editable: true, nullable: true },
PrjKy: { editable: true, nullable: true },
PrcsDetAprKy: { editable: true, nullable: true },
PrjNm: { editable: true, nullable: false, validation: { required: true} },
Des: { editable: true, nullable: false },
NxtActByAdr: { editable: true, nullable: false, validation: { required: true} },
NxtActByAdrKy: { editable: true, nullable: true },
NxtActDt: { editable: true, nullable: true },
Rem: { editable: true, nullable: true, type: "string" },
OriginBy: { editable: false, nullable: true },
Hyperlinks1: { editable: false, nullable: true },
Hyperlinks2: { editable: false, nullable: true },
Hyperlinks3: { editable: false, nullable: true },
Hyperlinks4: { editable: false, nullable: true },
OrginAdrKy: { editable: true, nullable: true },
WrkStnKy: { editable: true, nullable: true },
ObjKy: { editable: true, nullable: true },
ObjCd: { editable: true, nullable: true },
ObjNm: { editable: true, nullable: true },
ItmKy: { editable: true, nullable: true },
ItmCd: { editable: true, nullable: true },
IsAct: { editable: true, nullable: true },
IsApr: { editable: true, nullable: true },
OrgEntDt: { editable: true, nullable: true }
}
}
}
});
return dataSource;
}
采纳答案by Vojtiik
You can find quite clear explanation in here parameterMap
您可以在此处的parameterMap 中找到非常清楚的解释
You should use parametrMap to define custom set of parameters or perform additional operations during the call to remote service. Basically here you saying, if I am reading, updating or deleting (this is the operation variable of value "read" in your snippet) I want to add following parameter(s) to the methods I defined in "transport".
您应该使用 parametrMap 来定义自定义参数集或在调用远程服务期间执行其他操作。基本上在这里你说,如果我正在阅读、更新或删除(这是你的代码片段中值“读取”的操作变量),我想将以下参数添加到我在“传输”中定义的方法中。
In your case you didn't defined options.models so it seems, which means your datasource doesn't have any variable/collection models. Well it doesn't have to. To me it looks like the read method you trying to call doesn't really need any parameters so you might just return empty string from the paramMap or not to have this configuration section at all.
在您的情况下,您没有定义 options.models 所以看起来,这意味着您的数据源没有任何变量/集合模型。那么它没有必要。在我看来,您尝试调用的 read 方法实际上并不需要任何参数,因此您可能只从 paramMap 返回空字符串,或者根本没有此配置部分。
NOTE: the way you defined the datasource is bit confusing, you should not provide the configuration "data" when you defined the "url", eg. you are getting the data of the url. See Local vs Remote.
注意:您定义数据源的方式有点混乱,当您定义“url”时,您不应提供配置“数据”,例如。您正在获取网址的数据。请参阅本地与远程。
回答by Prem
ParameterMap, as defined in Kendo documentation, is a function which converts the request parameters to a format suitable for the remote service.
Kendo 文档中定义的 ParameterMap 是一个函数,它将请求参数转换为适合远程服务的格式。
In the format of the function, ParameterMap: function (options, operation){...}, the options parameter is a tricky one. In Kendo documentation, it is called data. However, developers choose to rename it as options as per their liking. However, no difference because it is just a parameter name.
在函数的格式ParameterMap: function (options, operation){...} 中,options 参数是一个棘手的问题。在 Kendo 文档中,它被称为数据。但是,开发人员选择根据自己的喜好将其重命名为选项。但是,没有区别,因为它只是一个参数名称。
The value of the optionsparameter depends upon what the transport section is doing. If it is a readoperation, then kendo automatically populates it with fields like skip, take, page, pagesizeetc. However, it depends whether the kendo grid has pagingset to true, sortingset to true etc. So, it is actually smart enough to take these parameters automatically and pass it to the service.
options参数的值取决于传输部分正在做什么。如果是读操作,那么kendo会自动用skip、take、page、pagesize等字段填充它。但是,这取决于kendo网格是否将分页设置为true,排序设置为true等。所以,它实际上很聪明足以自动获取这些参数并将其传递给服务。
In service, the function must be named exactly as what kendo names the parameter. Like skip, take, page etc by default. However, the parameter names can be changed by writing something like this: $top: data.take, as given in the documentation.
在服务中,函数的名称必须与剑道对参数的命名完全相同。默认情况下,如跳过、获取、翻页等。但是,可以通过编写如下内容来更改参数名称:$top: data.take,如文档中所述。
I am new to the concept as well and this is what I could gather. I wish I could get the below information in this article then it would have been a complete set.
我也是这个概念的新手,这是我可以收集的。我希望我能在这篇文章中获得以下信息,那么它就会是一个完整的集合。
- What is the complete list of options in case of read is paging and sorting set to true.
- What is the complete list of options in case of delete and update.
- 读取情况下的完整选项列表是分页和排序设置为true。
- 删除和更新的完整选项列表是什么。