我正在开发Kendo UI Treeview。目前我有一个要求,例如当父节点被尊重时,子节点被选中,其他父节点及其受尊重的子节点应被禁用(我的剑道树视图包含许多父节点和子节点)。
编辑:已添加代码
@(Html.Kendo().TreeView()
.Name("Countries")
.DataTextField("CityName")
.Events(e => {
e.Check("getSelecedFacilities");
e.DataBound("onDataBound");
})
.Checkboxes(checkboxes => checkboxes
.Name("cityCheck")
.CheckChildren(true)
)
.BindTo((IEnumerable<CountryModel>)ViewBag.Country, (Kendo.Mvc.UI.Fluent.NavigationBindingFactory<TreeViewItem> mappings) =>
{
mappings.For<CityModel>(binding => binding.ItemDataBound((item, parent) =>
{
item.Id = parent.Id.ToString();
item.Text = parent.Name;
item.HtmlAttributes.Add("class", "citycheck");
})
.Children(p => p.City));
mappings.For<CityModel>(binding => binding.ItemDataBound((item, child) =>
{
item.Id = child.Code;
item.Text = child.Name;
item.HtmlAttributes.Add("class", "citycheck");
}));
})
)
我使用的脚本:
function onDataBound() {
var checkedStatus = $(this).is(':checked');
if (checkedStatus) {
$('.citycheck li input[type="checkbox"]').not($(this).parent(".citycheck").find(".k-group .k-item input:checkbox[name=citycheck]")).attr('disabled', 'disabled');
}
else {
$(this).closest(".k-item").find(".k-group .k-item input:checkbox[name=citycheck]").each(function () {
$(this).prop('checked', false);
$("#Countries ul li div span:nth-of-type(2) input[type='checkbox'][name=citycheck]").removeAttr('disabled');
});
}
}