Custom Control Component failed to use up('target') navigation

We have written a custom control component (basically a Ext.form.FieldContainer which supply navigation buttons based on components he is a subchild of.)

As a example let us say it is a tabpanel and we want to add navigation buttons to jump to the next or previous tab and lets say we name our new components xtype navcontrol

We may have something like this:

{
    xtype: 'tabpanel',
    items: [{
        xtype: 'container',
        items: [{
            xtype: 'form',
            // our new component. It should create one Button
            dockedItems: [{xtype:'navcontrol'}] 
        }]
    },{
        xtype: 'container',
        items: [{
            xtype: 'form',
            // again our new component. It should create two Buttons
            dockedItems: [{xtype:'navcontrol'}] 
        }]
    },{
        xtype: 'container',
        items: [{
            xtype: 'form',
            // and again our new component. It should create one Button
            dockedItems: [{xtype:'navcontrol'}] 
        }]
    }]
}

Please do not tell me that this is overnesting and I can spare the containers; I just want to show that the navcontrol component is nested deeper.

What the navcontrol class needs to do is to acquire all necessary information from the next tabpanel up in the hierarchy. So our first try was to do this within the initComponent, cause we want to initialize our component. We added the appropriate code after the callParent call but no luck, this.up('tabpanel') returned null.

It seems like the Component didn't know his parent... My first thought: stupid

So based on the API we found onAdded which has the parent as argument and seems to set it. OK, this can makes sense. We prepare with initComponent and set related thing up with onAdded. We moved the code from the initComponent to the onAdded, again after the callParent call. And again it returned null!

So at which point (before rendering) are we able to query the hierarchy (without subscribing to a event the fire our self)?

Answers


Because initialization happens in this order:

  1. Container gets instantiated
  2. Container creates instances of child components/containers
  3. Container adds component/container to itself

So say you have A -> B -> C. By the time onAdded is called for C, it gets added to B, but B isn't yet added to A.

beforeRender would be a template method you could override where the container hierarchy will be setup.


Need Your Help

Efficient approach for sorting names from file?

algorithm sorting python-3.x

I am tackling an objective that requires me to sort a list of names (> 10,000) from a file. What is an efficient approach in accomplishing this? Names could vary in char length and I do not have to...

.NET Remoting vs. Web Services vs. Windows Communication Foundation (WCF)

asp.net wcf web-services remoting

Anyone willing to help me out with pros/cons on .NET Remoting, Web Services, and WCF? I have worked a bit with .NET Remoting and Web Services and I am architecting a new ASP.NET 3.5 web app where ...