Kendo MVC DropdownTree 不显示所选值
Kendo MVC DropdownTree not displaying selected value
我在 5 月页面中有一个 Kendo MVC DropdownTree。我成功地将选定的值从中保存到数据库中。当我开始编辑数据时,该值从模型中正确返回并设置在 DropdownTree 中,但是,在下拉树中没有视觉上选择任何项目。
当我尝试通过单击按钮读取下拉树的值时,它正确 returns 值。
@(Html.Kendo().DropDownTree()
.Name("VocationID")
.DataTextField("Name")
.DataValueField("Id")
.ValuePrimitive(true)
.Placeholder("--Select Vocation--")
.Value(Model.VocationID.ToString())
.DataSource(dataSource => dataSource
.Read(read => read
.Action("GetVocationTree", "ApplicationForm"))
)
.HtmlAttributes(new { style = "width: 250px;", required = "required", validationMessage = "Vocation is required" })
)
function TestValue() {
var dropdowntree = $("#VocationID").data("kendoDropDownTree");
alert(dropdowntree.value());
}
上面的 javascript 警报正确 returns 值但没有项目显示为在 DropdownTree 中选择。我也尝试删除 ValuePrimitive 属性,但没有任何效果。
有人可以帮忙确定这里缺少什么吗?
终于找到解决办法了。如果有一天它对某人有帮助,请发布它。
此控件的行为略有不同。您可以将所选项目读取为ID,但需要设置其文本而不是ID才能设置所选项目。
获取项目值:
var dropdowntree = $("#VocationID").data("kendoDropDownTree");
var VocationID = dropdowntree.value().id;
并设置默认值:
@(Html.Kendo().DropDownTree()
.Name("VocationID")
.DataTextField("Name")
.DataValueField("Id")
.Placeholder("--Select Vocation--")
.Value(Model.VocationName)
注意 "VocationName" 而不是 ID。
我在 5 月页面中有一个 Kendo MVC DropdownTree。我成功地将选定的值从中保存到数据库中。当我开始编辑数据时,该值从模型中正确返回并设置在 DropdownTree 中,但是,在下拉树中没有视觉上选择任何项目。
当我尝试通过单击按钮读取下拉树的值时,它正确 returns 值。
@(Html.Kendo().DropDownTree()
.Name("VocationID")
.DataTextField("Name")
.DataValueField("Id")
.ValuePrimitive(true)
.Placeholder("--Select Vocation--")
.Value(Model.VocationID.ToString())
.DataSource(dataSource => dataSource
.Read(read => read
.Action("GetVocationTree", "ApplicationForm"))
)
.HtmlAttributes(new { style = "width: 250px;", required = "required", validationMessage = "Vocation is required" })
)
function TestValue() {
var dropdowntree = $("#VocationID").data("kendoDropDownTree");
alert(dropdowntree.value());
}
上面的 javascript 警报正确 returns 值但没有项目显示为在 DropdownTree 中选择。我也尝试删除 ValuePrimitive 属性,但没有任何效果。
有人可以帮忙确定这里缺少什么吗?
终于找到解决办法了。如果有一天它对某人有帮助,请发布它。
此控件的行为略有不同。您可以将所选项目读取为ID,但需要设置其文本而不是ID才能设置所选项目。
获取项目值:
var dropdowntree = $("#VocationID").data("kendoDropDownTree");
var VocationID = dropdowntree.value().id;
并设置默认值:
@(Html.Kendo().DropDownTree()
.Name("VocationID")
.DataTextField("Name")
.DataValueField("Id")
.Placeholder("--Select Vocation--")
.Value(Model.VocationName)
注意 "VocationName" 而不是 ID。