我正在使用jstree库,我正在尝试了解如何在扩展一个节点后检查树的所有节点是否扩展。我要使用的此功能为了设置开/关气的天气,所有节点均已扩展或所有节点均未扩展。
如果要检查所有节点是处于折叠状态还是至少一个节点被扩展,则可以使用以下检查。
$('#btnCheck').click(function () {
$('#status').text("No - all nodes are collapsed");
if($('#SimpleJSTree li.jstree-open').length)
{
$('#status').text("Yes - there is expanded node");
}
});
jstree ID是SimpleJstree,并且正在使用Jstree-open类用于扩展节点。
以示例,您可以参考https://everything.com/jstree-check-for-any-pended-node
实际上使用jstree after_open 事件有一个解决方案(我尝试使用show_all事件,但这对我不起作用):
http://jsfiddle.net/softxide/1fnbzjjjf/15/
$('#container').on('after_open.jstree', function(e, data) {
var closed_count = $(".jstree-closed").length;
if(closed_count == 0)
{
alert("all opened");
}
}).jstree();