PDA

View Full Version : Single controller with multiple instances of same components



nareshmoorthy
23 Oct 2012, 4:55 AM
We are building an application where we show a tree and on right click of the tree node, we have an option to open up a Properties panel. Now it is a requirement to be able to open up Properties popup for multiple tree nodes at a time to compare values.

The Properties popup also has a grid and also some operations to be performed for which I have defined a controller. Since the refs defined in a controller will return back the first reference to the component, it is getting difficult to point to the correct component instances using refs when we have multiple Properties popups opened.

The alternative is to use the instances that are passed to event handler methods and work on them. Does this mean, the refs system cannot be used in such cases where we have multiple instances of the same components?

Also my code is turning out to having a lot of up() and down() methods when I need to update one component upon the event of another. Hope there is no performance penalty due to this.

Thanks.

James Goddard
23 Oct 2012, 5:51 AM
Assuming that this tree is dynamic (and not some limited fixed data set) I don't think you want to use refs here. but rather just go directly to Ext.ComponentQuery.

Something along the lines of:

Ext.ComponentQuery.query ('myPropertyPanel[treeItemId=' + treeItemId + ']');

If it is a small fixed set of data in the tree then you could still use refs for the panels:

{
ref: 'treeItem1Panel',
selector: 'myPropertyPanel[treeItemId=1]'
}

Tim Toady
23 Oct 2012, 6:50 AM
IMO, in this instance the preferable way is the way you are doing, which is using the first parameter passed to the event. I generally do that before creating a ref anyway if that is the only place I need it. While I don't know what your code looks like, I doubt the use of up and down has a significant effect on the performance unless you are doing it many many times. Ext's bottleneck is usually in the area of layout/rendering. Use a ref for items that you don't have multiple instances of or are easily targeted.

nareshmoorthy
23 Oct 2012, 8:59 AM
The controller in question is for the Property popup rather than the tree.

nareshmoorthy
23 Oct 2012, 9:02 AM
Yes seems like I should avoid using refs in such cases. Thx.