gpt4 book ai didi

kendo-treeview - 未捕获的类型错误 : Cannot read property 'dataSource' of undefined

转载 作者:行者123 更新时间:2023-12-03 22:52:33 24 4
gpt4 key购买 nike

我试图让 KendoTree View 使用复选框选项。我复制了完全相同的代码并添加了:

<link href="kendo/kendo.common.min.css" rel="stylesheet" />
<link href="kendo/kendo.default.min.css" rel="stylesheet" />
<script src="kendo/jquery.min.js" />
<script src="kendo/kendo.all.min.js" />

<script>
$("#treeview").kendoTreeView({
checkboxes: {
checkChildren: true
},

dataSource: [{
id: 1, text: "My Documents", expanded: true, spriteCssClass: "rootfolder", items: [
{
id: 2, text: "Kendo UI Project", expanded: true, spriteCssClass: "folder", items: [
{ id: 3, text: "about.html", spriteCssClass: "html" },
{ id: 4, text: "index.html", spriteCssClass: "html" },
{ id: 5, text: "logo.png", spriteCssClass: "image" }
]
},
{
id: 6, text: "New Web Site", expanded: true, spriteCssClass: "folder", items: [
{ id: 7, text: "mockup.jpg", spriteCssClass: "image" },
{ id: 8, text: "Research.pdf", spriteCssClass: "pdf" },
]
},
{
id: 9, text: "Reports", expanded: true, spriteCssClass: "folder", items: [
{ id: 10, text: "February.pdf", spriteCssClass: "pdf" },
{ id: 11, text: "March.pdf", spriteCssClass: "pdf" },
{ id: 12, text: "April.pdf", spriteCssClass: "pdf" }
]
}
]
}]
});

// function that gathers IDs of checked nodes
function checkedNodeIds(nodes, checkedNodes) {
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].checked) {
checkedNodes.push(nodes[i].id);
}

if (nodes[i].hasChildren) {
checkedNodeIds(nodes[i].children.view(), checkedNodes);
}
}
}

// show checked node IDs on datasource change
$("#treeview").data("kendoTreeView").dataSource.bind("change", function() {
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);
});
</script>

它给了我——

未捕获的类型错误:无法读取未定义的属性“dataSource”。

任何帮助都会很棒。

谢谢。
索努

最佳答案

在我看来,您错过了 html 中的控件,对我有用:
http://jsfiddle.net/vojtiik/L38KA/1/

<div id="treeview">
</div>

关于kendo-treeview - 未捕获的类型错误 : Cannot read property 'dataSource' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18105558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com