View Full Version : Referencing components

1 Nov 2010, 8:58 AM
I've been using Ext for about two years now and I can't say enough good things about it. So first off, thanks to all the developers involved in the project.

The main issue I have with my Ext code is in referencing components. Javascript scoping still confuses the hell out of me at times and I have a hard time resolving what "this" means in a given context. So to circumvent using the "this" keyword, the most common methods I use are supplying an id for use with Ext.getCmp() or assigning the component to a variable which can possibly lead to scoping issues if you aren't careful. Both methods just end up feeling clunky to me. It's weird having a bunch of Ext.getCmp()'s at the beginning of an anonymous event delegate and seems like there should be a cleaner way to reference components using the parent/items chain.

Also, I'm not sure of the best way to write/reference a component in a factory pattern. Supplying an id to a factory created component seems like it would make Ext.getCmp() ambiguous when more than one component is created (with the same id). So my solution is to create explicit references within the function's scope for every single component that I need to reference.

Does any of this make sense? Is there a best practice for component resolution or a more generic way to reference components?



1 Nov 2010, 9:06 AM
Have you seen Jays screencast (http://tdg-i.com/392/ext-js-screencast-the-dangers-of-ext-getcmp) on the matter?

1 Nov 2010, 10:07 AM
That hit the nail on the head. The itemId pattern seems to act like a scoped Ext.getCmp which is very useful. Thanks for the help. The this.property pattern seems the cleanest and my favorite, but requires a bit heavier object than what is sometimes required.