1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    11
    Vote Rating
    0
    aarondrabeck is on a distinguished road

      0  

    Question Set Panel config option at initialization with Sencha 2.0 broken?

    Set Panel config option at initialization with Sencha 2.0 broken?


    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
    Code:
    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:
    Code:
    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
                                        }
                                   }]
                }]
    ...

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,642
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1