Skip to content Skip to sidebar Skip to footer

Dojox's Jsonreststore Loading The Same Thing Several Times

I'm using a lazy loading tree in a web app project; however, I've ran into some strange behavior. It seems a simple tree with just 3 levels causes 7 requests for the root structure

Solution 1:

finally I found a solution to this problem, thanks to this post on dojo interest: thisisalink.

basically, with dojo 1.6 the dijit.tree.ForestStoreModel was extended with a few new hook-like functions (I guess because of the work done with the TreeGrid). One of these, onSetItem is called once a tree node is expanded (thus going form preLoaded to fully loaded when using a lazyLoading store). In the basic implementation, this function calls _requeryTop(), which requeries all root items.

for our application we could simply replace dijit.tree.ForestStoreModel with our implementation digicult.dijit.tree.ForestStoreModel, where onSetItem and onNewItem don't call this._requeryTop.

Sadly it's not enough to subclass the ForestStoreModel, as there are this.inherited(arguments); calls in the functions which can't be replaced easily, so we had to copy the whole class (copy class, rename, comment out two lines - easiest fix in a long time :-) ) - this may force us to redesign the class again once we update dojo to an even newer version.

Solution 2:

I've also faced the performance problems with dijit Tree when having a tree with 10000+ nodes to be all loaded at once, with ~3000 items at the very top level. The tree had only one dummy root node which loads the whole tree on the first click via ajax call.

In this case the tree creation took more than 1 minute to load and I got 'Stop running this script' dialog popup on IE8.

After applying a few optimization steps, the tree now loads within 2 seconds on all major browsers (IE8-IE11 included).

The first optimization I made was using dijit/tree/ObjectStoreModel as the tree's model and dojo/store/Memory as the data store.

This speeded up inserting the ajax response json nodes into the tree's data store.

The second optimization concerned the slow creation of the Tree's nodes. That took more efforts to fix:

I had to extend dijit/Tree and override the setChildItems() function (the part of it which calls _createTreeNode() function).

I kept the whole logic of the setChildItems() intact, just added parallelization of creating the tree nodes using this technique:

http://www.picnet.com.au/blogs/Guido/post/2010/03/04/How-to-prevent-Stop-running-this-script-message-in-browsers.aspx

Hope it helps, if needed, I can post the source code of my workaround

Post a Comment for "Dojox's Jsonreststore Loading The Same Thing Several Times"