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

Limit objects in a collection from being serialized based on User

c# entity-framework json.net asp.net-web-api2

I have a webapi that returns an object that contains some collections of objects which also contains a collection of objects. Each of these objects has a bool that represents if the object is 'publ...