Kendo Jquery 外键下拉列表值
Kendo Jquery ForeignKey Dropdownlist values
我的应用程序是 MVC 5,使用 Kendo UI Jquery 可编辑网格。其中一列是下拉列表,使用:
{ field: "ApplicableCourse_ID", title :"Course", values: myDDL1 }
我使用以下 Ajax 生成值数组 myDDL1
$.ajax({
url: '@Url.Action("GetFreeAccessDropdownList", "fff")',
type: "GET",
async: false,
cache: false,
dataType: "json",
success: function (result) {
myDDL1.push(JSON.stringify(result.Grid1));
var grid = $("#grid").data("kendoGrid");
grid.refresh();
},
error: function (request, status, error) {
alert(request.responseText);
}
});
我得到了正确的值和文本:
但是;网格显示值而不是文本。如果我使用静态数组:
var myDDL1 = [
{ "value": 54, "text": "Fuel Spill Response Plan" },
{ "value": 56, "text": "Community Fuel Contractor Manual" },
{ "value": 91, "text": "Blocking and Cribbing" }];
显示正确的文本。动态数组和静态数组有区别吗?
填充集合后调用网格的 refresh() 方法是不够的,因为它不会刷新模板和外键列。
有两种选择:
- 直接从列中进行 AJAX 调用,无需处理成功回调:
Remote data binding for foreign key
- 设置网格数据源autoBind property of the grid to false. Inside the success callback of your custom AJAX, call the fetch() method
以防其他人遇到这个问题;我使用的解决方案是在控制器中生成一个 ViewBag 列表:
var grid1 = db.Courses.Select(c => new
{
value = c.ID,
text = c.Name,
}).ToList();
ViewBag.Course = grid1;
在视图中
var myDDL1 = @Html.Raw(Json.Encode(ViewBag.Course));
网格列
field: "ApplicableCourse_ID", filterable: { multi: true, search: true }, values: myDDL1
我的应用程序是 MVC 5,使用 Kendo UI Jquery 可编辑网格。其中一列是下拉列表,使用:
{ field: "ApplicableCourse_ID", title :"Course", values: myDDL1 }
我使用以下 Ajax 生成值数组 myDDL1
$.ajax({
url: '@Url.Action("GetFreeAccessDropdownList", "fff")',
type: "GET",
async: false,
cache: false,
dataType: "json",
success: function (result) {
myDDL1.push(JSON.stringify(result.Grid1));
var grid = $("#grid").data("kendoGrid");
grid.refresh();
},
error: function (request, status, error) {
alert(request.responseText);
}
});
我得到了正确的值和文本:
但是;网格显示值而不是文本。如果我使用静态数组:
var myDDL1 = [
{ "value": 54, "text": "Fuel Spill Response Plan" },
{ "value": 56, "text": "Community Fuel Contractor Manual" },
{ "value": 91, "text": "Blocking and Cribbing" }];
显示正确的文本。动态数组和静态数组有区别吗?
填充集合后调用网格的 refresh() 方法是不够的,因为它不会刷新模板和外键列。
有两种选择:
- 直接从列中进行 AJAX 调用,无需处理成功回调:
Remote data binding for foreign key
- 设置网格数据源autoBind property of the grid to false. Inside the success callback of your custom AJAX, call the fetch() method
以防其他人遇到这个问题;我使用的解决方案是在控制器中生成一个 ViewBag 列表:
var grid1 = db.Courses.Select(c => new
{
value = c.ID,
text = c.Name,
}).ToList();
ViewBag.Course = grid1;
在视图中
var myDDL1 = @Html.Raw(Json.Encode(ViewBag.Course));
网格列
field: "ApplicableCourse_ID", filterable: { multi: true, search: true }, values: myDDL1