View Full Version : Can I ComponentQuery in the constructor?

26 Sep 2012, 10:10 AM
I am trying the following in the constructor of an extended container:

constructor: function (config) {
config = config || {};
var tbl = this.down('#mainTable');

throws TypeError: items is undefined, although this.items has the expected items

Is it even possible here? If not where, an event e.g. before/after render...?

26 Sep 2012, 10:12 AM
No, you have to wait until the items collection is built

26 Sep 2012, 11:29 PM
I'd completely forgotten about initComponent.

Here's a question, do you real like a slug sucking salt when seeing this:


as opposed to

Ext.applyIf(this, {
items: [{cmp

in initComponent? or is it just a matter of preference? with JS being the language it is there's always 16.2 ways to skin a tiger and knowing what's the convention is quite tough..obviously that will come with XP.

27 Sep 2012, 4:32 AM
It's all about what you can do at the point where you are doing it. If you can just set the items property then that is preferred but if not then you would have to do the this.add()