PDA

View Full Version : Ext.extend: items in config object or in InitComponent?



JacobGu
4 Mar 2011, 5:40 AM
There is a difference between Touch and ExtJS 3.x in how one defines items for an Ext.Container extension. In Touch, one can specify items directly in the config object passed to Ext.extend, as in:

my.Container = Ext.extend(Ext.Container, {
....
items: [{
....
}]
....
});

This means that the items array can be set when the constructor is called.

However, that won't work in Ext JS 3.x. (I don't know about 4.x.) In Ext JS, the Container expects the items array to be set after the constructor and before initComponent. Otherwise, items will never become a MixedCollection that is necessary to render.

Is that just a limitation of the older Ext JS codebase? Did Sencha consciously move away from that in Touch? What is behavior in Ext JS 4.x?

6 Mar 2011, 7:12 AM
I generally place items in a factory method and assign them in the initComponent. This adds flexibility for your code to do change config options on the fly if it wants to.