我有一个剑道组合盒,有两个值:主,次。我也有一个Kendo变异选择链接到一个数据源。默认情况下,组合框显示“主”和多选择显示“Parent2 1”,“Parent2”,即数据源的“‘Name”字段。
如果用户从组合框中选择‘dataTextField’,则动态地将multiselect的Name2更改为Name2,类似地,当用户从下拉列表中选择'Main‘时,multiselect应该链接到'Name’作为其dataTextField。
这是小提琴
<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>发布于 2015-04-30 18:55:17
Kendo小部件通常围绕目标元素创建包装器结构,不是由方法destroy()破坏的(我认为这是一件坏事)。
因此,销毁(或从DOM中删除)小部件并不是那么简单。看看这个:
function createMainCategory(usersDiv, textField, valueField, remove)
{
var mc = $("#MainCategory");
if (remove)
{
// Destroys the widget
mc.data("kendoMultiSelect").destroy();
// Get the widget wrapper element structure
var p = mc.closest(".k-widget");
// Detache the #MainCategory from the wrapper structure
mc = mc.empty().detach();
// Remove the wrapper structure
p.remove();
// Append the #MainCategory to the body again
$('body').append(mc);
}
$("#MainCategory").kendoMultiSelect({
dataSource: [
{ Name: "Parent1", Id: 1, Name2: "Child1" },
{ Name: "Parent2", Id: 2, Name2: "Child2" }
],
dataTextField: textField,
dataValueField: valueField
});
}如你所见,在删除块中.
destroy()销毁小部件;#MainCategory ( detach()移除但返回其对元素的进一步操作的引用);#MainCategory安全,它可以从DOM获得包装器的整个结构;#MainCategory再次添加到主体上,用于托管新的小部件。小提琴。
https://stackoverflow.com/questions/29973184
复制相似问题