Jquery 带复选框的剑道UI树视图,分层数据源未完全加载
使用上的示例,我现在有以下代码Jquery 带复选框的剑道UI树视图,分层数据源未完全加载,jquery,treeview,hierarchical-data,Jquery,Treeview,Hierarchical Data,使用上的示例,我现在有以下代码 <script> var dataSource = new kendo.data.HierarchicalDataSource({ data: [ { id: 1, text: "Useraccess", expanded: true, items: [ { id: 2, text: "Roles", items: [
<script>
var dataSource = new kendo.data.HierarchicalDataSource({
data: [
{
id: 1, text: "Useraccess", expanded: true, items: [
{ id: 2, text: "Roles", items: [
{ id: 3, text: "Access", checked: true },
{ id: 4, text: "Edit", checked: true }
]},
{ id: 5, text: "Users", items: [
{ id: 6, text: "Access" },
{ id: 7, text: "Edit" }
]}
]
},
{
id: 8, text: "Customer", expanded: true, items: [
{ id: 9, text: "Customer", items: [
{ id: 10, text: "Access" },
{ id: 11, text: "Edit", checked: true }
]},
{ id: 12, text: "Account", items: [
{ id: 13, text: "Access" },
{ id: 14, text: "Edit" }
]}
]
}
]
});
$("#treeView").kendoTreeView({
checkboxes: {
checkChildren: true
},
dataSource: dataSource
});
// function that gathers IDs of checked nodes
function checkedNodeIds(nodes, checkedNodes) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].checked && !nodes[i].hasChildren) {
checkedNodes.push(nodes[i].id);
}
if (nodes[i].hasChildren) {
checkedNodeIds(nodes[i].children.view(), checkedNodes);
}
}
}
function refreshResult() {
var checkedNodes = [],
treeView = $("#treeView").data("kendoTreeView"),
message;
checkedNodeIds(treeView.dataSource.view(), checkedNodes);
if (checkedNodes.length > 0) {
message = "IDs of checked nodes: " + checkedNodes.join(",");
} else {
message = "No nodes checked.";
}
$("#result").html(message);
}
// show checked node IDs on datasource change
$("#treeView").data("kendoTreeView").dataSource.bind("change", function() {
refreshResult();
});
refreshResult();
</script>
当我在Treeview中定义数据源时,结果文本将显示所选的正确节点。有没有办法模拟这种行为?我计划将来使用远程数据。我在TreeView API中找到了答案。答案如下: 所以我需要在树视图中设置loadOnDemand:false:
$("#treeview").kendoTreeView({
checkboxes: {
checkChildren: true
},
dataSource: [
{
id: 1, text: ....
$("#treeView").kendoTreeView({
loadOnDemand: false, ...