我有一个CostCenter组合框,试图从CompanyCode组合框中获取所选项目的ID,并将其传递到URL,但我不明白为什么我在URL中总是保持“未定义”。
--- JS ---
$("#companyCode").width(500).kendoComboBox({
placeholder: "Select...",
dataTextField: "CompanyDescription",
dataValueField: "Id",
autobind: false,
template: "#: data.CompanyCode# - #: data.CompanyDescription#",
dataSource: {
serverFiltering: true,
transport: {
read: {
url: "./CompanyCodeCostCenter/GetAll",
// the request type
type: "get",
// the data type of the returned result
dataType: "json",
}
}
},
change: function () {
companyCodeId = this.value();
}
});
$("#costCenter").width(500).kendoComboBox({
placeholder: "Select...",
dataTextField: "CostCenterDescription",
dataValueField: "Id",
template: "#: data.CostCenterNo# - #: data.CostCenterDescription#",
autobind: false,
cascadeFrom: "companyCode",
dataSource: {
serverFiltering: true,
transport: {
read: {
url: "./CompanyCodeCostCenter/Get" + companyCodeId,
// the request type
type: "get",
// the data type of the returned result
dataType: "json",
},
parameterMap: function (data, type) {
if (type == "read" &&
data.filter != undefined &&
data.filter.filters != undefined ){
var filter = data.filter.filters;
return {
id: filter[0].value,
}
}
}
}
}
});
---控制器---
public virtual JsonResult Get(int id)
{
SetUser();
var vo = _viewService.Get(id);
ExpirePage();
return Json(vo, JsonRequestBehavior.AllowGet);
}
---结果---
http://localhost/Tax/CompanyCodeCostCenter/Getundefined?id=21
我对JS和Kendo非常陌生。如果可能,请详细说明。谢谢
我认为这篇文章应该可以帮助您实现所需的目标:https://docs.telerik.com/kendo-ui/controls/editors/combobox/cascading#what-to-do-when-i-cannot-get-the-request-parameters-on-the-server
$("#costCenter").width(500).kendoComboBox({
placeholder: "Select...",
dataTextField: "CostCenterDescription",
dataValueField: "Id",
template: "#: data.CostCenterNo# - #: data.CostCenterDescription#",
autobind: false,
cascadeFrom: "companyCode",
dataSource: {
serverFiltering: true,
transport: {
read: {
url: "./CompanyCodeCostCenter/Get" + companyCodeId,
// the request type
type: "get",
// the data type of the returned result
dataType: "json",
// use this instead of parameter map
data: function () {
return { id: $('#companyCode').val() }
}
}
}
}
});
我将data
属性添加到transport.read
对象。