我有一个具有两个值的剑道组合框:主要、次要。我还有一个链接到数据源的 Kendo 多选。默认情况下,组合框显示“Main”,多选显示“Parent1”、“Parent2”,即数据源的“Name”字段。
如果用户从组合框中选择“辅助”,我想将多选的 dataTextField 动态更改为 Name2,同样,当用户从下拉列表中选择“主”时,多选应链接到“名称”作为其 dataTextField。
这是小提琴
HTML
<select id="CategoryOption" style="width: 100px;">
<option>Main</option>
<option>Secondary</option>
</select> <br><br><br><br><br><br>
<select id="MainCategory" style="width: 90%;"></select>
Java 脚本
createCategoryOption("#CategoryOption");
createMainCategory("#MainCategory", "Name", "ID");
function createCategoryOption(divID1)
{
$(divID1).kendoComboBox({
change: function (e) {
SetSelectServicesText();
}
});
}
function createMainCategory(usersDiv, textField, valueField) {
$("#MainCategory").kendoMultiSelect({
dataSource: [
{ Name: "Parent1", Id: 1, Name2: "Child1" },
{ Name: "Parent2", Id: 2, Name2: "Child2" }
],
dataTextField: textField,
dataValueField: valueField
});
}
function SetSelectServicesText()
{
if($("#CategoryOption").data("kendoComboBox").value() == "Main")
{
$("#MainCategory").destroy();
createMainCategory("#MainCategory", "Name", "ID");
}
else
{
$("#MainCategory").destroy();
createMainCategory("#MainCategory", "Name2", "ID");
}
}
外部来源
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.dataviz.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.dataviz.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.mobile.all.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2015.1.408/js/kendo.all.min.js"></script>