dynatree - 使用延迟加载扩展键路径

标签 dynatree jquery-dynatree

我有一个包含多个项目和多个级别的完整树,该树是通过 ajax 调用构建的并使用惰性节点

所以现在我想添加该功能,以便我的树可以加载并选择项目,如果我给出完整路径,但在我可以选择项目之前,我需要确保该项目是通过延迟加载加载的,这样我就可以访问它。

我找到了函数 .loadKeypath(),因此为了测试,我使用

检索了节点的完整路径
node.getKeyPath();

所以路径是/12/16/17/18

所以我发现我应该在ajax数据加载之后放置这段代码

onPostInit: function(isReloading, isError){
                $("#tree").dynatree("getTree").loadKeyPath("/12/16/17/18", function(node, status){
                    if(status == "loaded") {
                        // 'node' is a parent that was just traversed.
                        // If we call expand() here, then all nodes will be expanded
                        // as we go
                        node.expand();
                    }else if(status == "ok") {
                        // 'node' is the end node of our path.
                        // If we call activate() or makeVisible() here, then the
                        // whole branch will be exoanded now
                        node.activate();
                    }else if(status == "notfound") {
                        var seg = arguments[2],
                            isEndNode = arguments[3];
                    }
                });
            }

但现在我在控制台中收到此警告:

Node not found: 12 jquery.dynatree.js:49

这是完整的日志

9:12:27.862 - Dynatree._create(): version='$Version: 1.2.0$', debugLevel=2. jquery.dynatree.js:52
9:12:27.865 - DynaTree.persistence: 
Object
 jquery.dynatree.js:52
9:12:27.867 - Dynatree._load(): read tree structure... jquery.dynatree.js:52
9:12:27.868 - Dynatree._init(): send Ajax request... jquery.dynatree.js:52
9:12:27.869 - Class.create.removeChildren(false) jquery.dynatree.js:52
9:12:27.876 - Dynatree._load(): render nodes... jquery.dynatree.js:52
9:12:27.877 - Dynatree._load(): bind events... jquery.dynatree.js:52
9:12:27.885 - Dynatree._load(): postInit... jquery.dynatree.js:52
9:12:27.887 - Dynatree._init(): done. jquery.dynatree.js:52
9:12:27.889 - ui.dynatree._init() was called; no current default functionality. jquery.dynatree.js:52
9:12:29.483 - Removed leading root key. jquery.dynatree.js:52
9:12:29.484 - Class.create._loadKeyPath(12/16/17/18) jquery.dynatree.js:52
9:12:29.484 - Node not found: 12 jquery.dynatree.js:49
9:12:29.485 - trigger nodeLoaded.dynatree.tree._1 jquery.dynatree.js:52
9:12:29.485 - dtnode._expand(true) IGNORED - 
Class.create
 jquery.dynatree.js:52

那么我如何加载嵌套在其他节点中的节点

最佳答案

这是一个供将来引用的答案

经过一些调试和 dynatree 开发人员的帮助,我们想出了一个解决方案,如果您想加载关键路径,请使用字符串作为键而不是整数。

而不是

 "icon": false,
        "checkbox": false,
        "title": "xxxxxxxx",
        "key": 23,
        "type": "child"

使用

 "icon": false,
        "checkbox": false,
        "title": "xxxxxxxx",
        "key": "23",
        "type": "child"

这样 loadkeypath 函数就会选择正确的路径!

关于dynatree - 使用延迟加载扩展键路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12490082/

相关文章:

javascript - 具有真实复选框的 Dynatree

javascript - 过滤动态树中的节点

javascript - 如何将焦点设置在 dynatree 标题中的输入字段上

javascript - 如何重新加载/刷新/重新初始化 DynaTree?

jQuery - dynatree 延迟加载和多层(类型 3)selectMode

css - 尽管有足够的垂直空间,为什么我的 div 显示垂直滚动条

jquery - 如何在动态树的延迟加载中加载孙子?

jquery - 如何使用 jQuery 选择 anchor 标记内的文本