1. #1
    Ext JS Premium Member
    Join Date
    Jun 2011
    Location
    Ottawa, Ontario, Canada
    Posts
    123
    Vote Rating
    1
    whalethewise is on a distinguished road

      0  

    Default items is undefined during different component initialization

    items is undefined during different component initialization


    Hi

    In 4.0.7 I was able to add child components in initComponent function. For example for Tab Panel

    Now with 4.1 it gives me 'items is undefined' error in getRefItems() function of AbstractContainer when I do not specify items in the config init and trying to add it in initComponent function for this TabPanel. Any suggestions?

    Thanks

    Code:
    Ext.create('Ext.tab.Panel', {
        width: 400,
        height: 400,
        renderTo: document.body,
        initComponent: function() {
        this.items =  [{        title: 'Foo'
        }, {
            title: 'Bar',
            tabConfig: {
                title: 'Custom Title',
                tooltip: 'A button tooltip'
            }
        }]
    
    
            this.callParent(arguments);
        }
    });

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,920
    Vote Rating
    632
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    You really shouldn't be overriding a method inline like that, what's the reasoning for doing so?
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Ext JS Premium Member
    Join Date
    Jun 2011
    Location
    Ottawa, Ontario, Canada
    Posts
    123
    Vote Rating
    1
    whalethewise is on a distinguished road

      0  

    Default


    it was my understanding that using initcomponent is a safe approach if I would like initialize something before instanriate. or I can do it only for define?

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,596
    Vote Rating
    324
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Overriding initComponent in an Ext.define is fine, just not in Ext.create.

    Generally, overriding a method in an Ext.create is bad practice but occasionally it is very convenient. If you do it directly (the way you have in your example) then callParent won't work correctly, or at least not reliably. 4.1 introduces a concept called xhooks to solve this problem. Take a look at Don's SenchaCon video for more info on this.

Thread Participants: 2