jsTree-在扩展所有节点之前呈现它们? [英] jsTree - render all nodes before they are expanded?

查看:127
本文介绍了jsTree-在扩展所有节点之前呈现它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当树中选择一个项目时,我试图在单独的div(.childNodes)中显示jsTree父级的所有后代的标题.我的问题是,后代似乎是延迟加载的,并且仅在扩展节点时才在DOM中渲染,而不是在选择节点时才渲染.有没有一种方法可以禁用此功能以在扩展父级之前渲染所有节点?

I'm trying to display the titles of all descendants of a jsTree parent in a separate div (.childNodes) when an item is selected in the tree. My issue is that the descendants are seemingly being lazy loaded, and are only rendered in the DOM when a node is expanded, not when it is selected. Is there a way to disable this to render all nodes before the parent is expanded?

这就是我创建树的方式:

This is how I'm creating the tree:

container.jstree({
'core': {
    'data': {
        'url': nodesContent,
    }
}});

这就是我处理选定事件的方式:

And this is how I'm handling the selected event:

container.on("changed.jstree", function (e, data) {
var i,
    list = "<ul>";
var children = data.instance.get_children_dom(data.selected[0]);
for (i = 0; i < children.length; i++) {
    list += "<li>" + children[i].innerHTML + "</li>";
}
list += "</ul>";
jQuery(".childNodes").html(list);});

谢谢.

推荐答案

否,不能禁用它-DOM中仅保留可见节点,但是您可以执行文档中建议的操作并与内部jstree模型一起使用检索标题.

No it can not be disabled - only visible nodes are kept in the DOM, you can however do what is recommended in the docs and work with the internal jstree model to retrieve the titles.

container.on("changed.jstree", function (e, data) {
    var i,
        list = "<ul>";
        children = data.instance.get_node(data.selected[0]).children;
    for (i = 0; i < children.length; i++) {
        list += "<li>" + data.instance.get_node(children[i]).text + "</li>";
    }
    list += "</ul>";
    jQuery(".childNodes").html(list);
});

如果要显示所有后代(不仅是立即生成的),请替换:
data.instance.get_node(data.selected[0]).children
与:
data.instance.get_node(data.selected[0]).children_d

If you want to display all descendants (not only immediate) substitute:
data.instance.get_node(data.selected[0]).children
with:
data.instance.get_node(data.selected[0]).children_d

这篇关于jsTree-在扩展所有节点之前呈现它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆