View Full Version : [OPEN-1430] TreeLoader.preloadChildren doesn't work as advertised

12 Nov 2010, 4:22 AM
This is an issue that has been raised before [1], but never really solved. It's either a definitive bug, or should result in a documentation change.

The problem is that the docs for preloadChildren say "If set to true, the loader recursively loads 'children' attributes when doing the first load on nodes." This isn't true when you load the root node, but it is on subsequent loads.

The problem is that TreeLoader's doPreload is invoked *before* the initial call to fetch data, so the 'first load' doesn't result in any preloading because there's no data yet. doPreload isn't invoked again until a subsequent node is loaded, and then things behave as expected.

I've made a quick fix by inserting a callback on the initial ajax request if preloadChildren is true. This means that doPreload is invoked again once the response comes back. It's not exactly elegant, but it works.

A testcase and my fix can be found at http://matt.bennett.name/treeloader

[1] http://www.sencha.com/forum/showthread.php?50079-2.0-CLOSED-Preload-Children-On-Tree-Doesn-t-Work-More-Than-A-Depth-Of-1