开发者

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 ju开发者_运维技巧st 3 levels causes 7 requests for the root structure. After looking at the official JRS tree test, I'm not sure whether this is normal or not.

Have a look at this example: http://download.dojotoolkit.org/release-1.6.1/dojo-release-1.6.1/dijit/tests/tree/Tree_with_JRS.html

When I visit it, my browser makes 5 requests for the root structure. My only question is why?

Edit: Worth mentioning is this doesn't happen with dojo 1.5 or below.

Here's what it looks like in the inspector (Chrome):

Dojox's JsonRestStore loading the same thing several times


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜