expanding keypath with lazyloading

950 views
Skip to first unread message

barabas

unread,
Sep 19, 2012, 9:00:03 AM9/19/12
to dyna...@googlegroups.com
I have a full tree with multiple items and multiple levels, the tree is build with an ajax call and uses lazy nodes

So now i want to add the function so my tree can load and select and item if i give the full path, but before i can select the item i need to make sure that the item is loaded with  lazy loading so i can access it.

I found the function .loadKeypath(), so for testing i retrieved the full path to my node with 

   
node.getKeyPath();


so the path is /12/16/17/18

So i figured out i should put this code after the ajax data was loaded in

   
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];
                       
}
                   
});
               
}


But now i get this warning in the console:

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

Adn this is the full log

    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

So how can i load a node what tis nested in other nodes

mar10

unread,
Sep 20, 2012, 1:45:09 AM9/20/12
to dyna...@googlegroups.com
node #12 must already exist on the top level and flagged as 'lazy' for this to work

barabas

unread,
Sep 20, 2012, 2:26:56 AM9/20/12
to dyna...@googlegroups.com
This is the data i havefor my dynatree


the root elements (firts nodes) and the children of the root items are loaded directly, all the deeper nodes are loaded with lazy loading. So i want to select the item(key) that is saved in the db, which can be an root item or the deepest nested node. That why i wanted to use the function loadKeyPath.

Is this the right way or can i do it better by using an other function?

Thanks in advance!

Op donderdag 20 september 2012 07:45:09 UTC+2 schreef mar10 het volgende:

mar10

unread,
Sep 20, 2012, 1:06:14 PM9/20/12
to dyna...@googlegroups.com
hmm looks ok at the first glance.
You could try to use string-keys, istead of integers, i.e. key: "12" instead of key: 12

barabas

unread,
Sep 21, 2012, 2:43:22 AM9/21/12
to dyna...@googlegroups.com
I passed the keys values as a string to json and now it works correct, thanks you very much! I posted a question on stackoverflow to so i will reply myself for future reference

http://stackoverflow.com/questions/12490082/expanding-keypath-with-lazyloading

Op donderdag 20 september 2012 19:06:14 UTC+2 schreef mar10 het volgende:

mar10

unread,
Sep 21, 2012, 9:01:16 AM9/21/12
to dyna...@googlegroups.com
If you like, you could open an issue for this - it feels like a bug ;-)

b.ka...@gmail.com

unread,
Oct 11, 2012, 3:28:59 AM10/11/12
to dyna...@googlegroups.com
Hi,

I also tried to use loadKeyPath(). But node did not load. What I understand it doesn't load because of race condition between child and parent node. How to resolve this problem?

Thanks,
Bhushan

mar10

unread,
Oct 11, 2012, 1:18:26 PM10/11/12
to dyna...@googlegroups.com, b.ka...@gmail.com
maybe the problem only occurs, when you call loadKeyPath() in onPostInit?
In this case you could try to decouple it (using setTimeout(...)) and also create an issue for this bug...
Reply all
Reply to author
Forward
0 new messages