Results 1 to 4 of 4

Thread: items is undefined during different component initialization

  1. #1
    Ext JS Premium Member
    Join Date
    Jun 2011
    Location
    Ottawa, Ontario, Canada
    Posts
    123
    Vote Rating
    1
      0  

    Default 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
    18,384
    Vote Rating
    858
      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
      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,790
    Vote Rating
    390
      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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •