遍历所有dataItems(所有kendo ui treeview节点) [英] iterate through all dataItems (all kendo ui treeview nodes)
问题描述
我试图在kendo ui树视图中简单地遍历我的所有节点.
I am trying to simply loop through all my nodes in a kendo ui treeview.
当前GetNodes()
返回的不是函数.我如何访问该列表?
Current GetNodes()
is returning not a function.. how can I access that list?
我也尝试过.get_allNodes();
-树是准确的,只是不要在哪里遍历当前节点.
I have also tried .get_allNodes();
- tree is accurate, just don't where to iterate trough current nodes.
let tv = $("#tree").data("kendoTreeView");
let nodes = tv.GetNodes();
console.log(nodes);
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].get_nodes() != null) {
console.log(nodes[i]);
let item = tv.dataItem(nodes[i]);
console.log(item);
let hasChildren = item.hasChildren;
console.log(hasChildren);
if (hasChildren = false){
tv.remove(item);
}
}
}
我的控制台树状视图,我看到了...
my consoled treeview i see this...
推荐答案
我根本不认识Kendo,所以我阅读了文档,希望对您有所帮助.
I didn't know Kendo at all, so I read the documentation and hope it will help you.
我通过文档重新创建了一个最小的示例,它可以正常工作.我以递归方式读取了数据源及其所有子对象.
I recreated a minimal example via the documentation and it works. I read the datasource with all its children recursively.
$(document).ready(function() {
$("#treeView").kendoTreeView({
dataSource: [
{
text: "Item 1",
items: [
{ text: "Item 1.1" },
{ text: "Item 1.2" }
]
},
{ text: "Item 2" }
]
});
var treeView = $("#treeView").data("kendoTreeView");
function recursiveReading(nodes) {
for (var i = 0; i < nodes.length; i++) {
console.log(nodes[i].text);
if (nodes[i].hasChildren)
recursiveReading(nodes[i].children.view());
}
}
recursiveReading(treeView.dataSource.view());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://kendo.cdn.telerik.com/2020.3.915/styles/kendo.common.min.css" rel="stylesheet" />
<script src="https://kendo.cdn.telerik.com/2020.3.915/js/kendo.all.min.js"></script>
<ul id="treeView">
</ul>
这篇关于遍历所有dataItems(所有kendo ui treeview节点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!