使用延迟加载扩展keypath

时间:2012-09-19 07:15:25

标签: 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

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

1 个答案:

答案 0 :(得分:4)

这是未来参考的答案

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

而不是

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

使用

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

这样,loadkeypath函数将拾取正确的路径!