PDA

View Full Version : Set Panel config option at initialization with Sencha 2.0 broken?



aarondrabeck
23 Oct 2011, 10:21 PM
In Sencha 1.0 I frequently would set configuration options at initialization on Extended objects like below. This was extremely helpful because only after initialization would the object be able to call the instantiated instance of itself via var self = this;. However in 2.0 I cannot seem to get this working at all. I see that initComponent was renamed initialize and I have accounted for that. It seems that initialize is called but "Ext.apply(this, { ... })" does not seem to work. Has anyone found a way to do this?

I do not want to assign ID's because these components need to be reusable.

Sencha 1.0 Example


ViewPort = Ext.extend(Ext.Panel, {
initComponent: function () {
var self = this;
Ext.apply(this, {
items: [ {
xtype: 'panel',
layout: 'card',
dockedItems: {
xtype: 'toolbar',
dock: 'top',
title: "Devices",
items: [{
xtype: 'button',
iconMask: true,
iconCls: 'refresh',
handler: function () {
self.UpdateMe();
self.hide();
self.show();
self.aware
}
}]
},
...


Sencha 2.0 fails to work like so:


Ext.define('ViewPort', {
extend: 'Ext.Panel',
initialize: function() {
var self = this;
console.log(self);
Ext.apply(this, {
config: {
items:[ {
xtype: 'toolbar',
docked: 'top',
title: 'Devices',
items: [{
xtype: 'button',
iconMask: true,
iconCls: 'refresh',
handler: function () {
self.UpdateMe();
self.hide();
self.show();
self.aware
}
}]
}]
...

mitchellsimoens
24 Oct 2011, 4:11 AM
This is not the way to do it. Things are rendered at a much earlier stage so you can do one of two things...

Have your config as a property of the class you are defining minus the ones you want to create. Then in your initialize method, use the setter that gets automatically created.

You can create your config object in the constructor before you callParent call. If you wait till after callParent, it's already rendered.