我正在尝试遍历jstree中树视图内的每个节点。树视图的深度为4级,但我似乎无法超越1级。以下是用于迭代的jQuery。
$("#myTree").bind('ready.jstree', function (event, data) {
$('#myTree li').each(function () {
// Perform logic here
}
});
});
这是一个说明我观点的jsfiddle。请帮助我如何遍历jstree中的每个节点。
这样可以将树的所有子级以平面数组的形式存储在.each
循环中。
$("#tree").bind('ready.jstree', function(event, data) {
var $tree = $(this);
$($tree.jstree().get_json($tree, {
flat: true
}))
.each(function(index, value) {
var node = $("#tree").jstree().get_node(this.id);
var lvl = node.parents.length;
var idx = index;
console.log('node index = ' + idx + ' level = ' + lvl);
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句