PDA

View Full Version : Waiting for treePanel to complete a node expand



gnube
10 Nov 2011, 2:53 PM
I have requirement for a stream synchronous code which will expand a tree node and then perform operations upon that (expended) node.

There is an 'itemexpand' event available, but I do not want to be acting upon this outside of this line of processing. I could use a member variable to flag an event handler to go ahead and continue my line of processing I guess; but that feels messy to me - I can't think of an alternative myself at the moment.

Is there a mechanism I can use to handle waiting for the expand to complete before continuing with my logic inline? In principle like:

expand(animateFlag, { itemexpand: function(){...}});

If there is a glaringly obvious answer to this it would not surprise me - still finding my feet in this environment..

Cheers

skirtle
11 Nov 2011, 3:54 AM
What do you mean by 'complete'? Do you mean wait for the animation to finish or just wait for all the nodes to be loaded and the animation to have started?

For the latter you can just pass it a callback:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.NodeInterface-method-expand

Note however that this will not necessarily be synchronous. It depends on whether it needs to load the nodes remotely. If you really need it to be synchronous you're going to struggle.

gnube
11 Nov 2011, 5:45 AM
Yep - I mean I want to pick execution back up again after the branch has been loaded from the remote store - I'll have a look at the callback stuff.

I the main reason I am looking at this is because from time to time I am seeing a 'duplicate' node appearing in my try when I append a new child programatically. The store is only getting one new row added, and if I close the tree and create a new one from my store it draws fine. I figure three is just some 'double handling' of asynchronous events going on and I am trying to circumvent that. I am pretty sure it is just a timing thing because it only happens on the odd occasion.

I need to look at callbacks at some stage to see how they work so now is as good a time as any.

Cheers

gnube
11 Nov 2011, 4:58 PM
Thanks skittle, callback seems to have done the trick for me - I had never used one before but I should have seen that on the API - my bad.