0

my code is basically like this.

Ext.define('my.class.name', 
{
    extend:'Ext.grid.Panel',
    variable:'',
    constructor: function(config)
    {
       variable = config.field;
    },
    items:[{
        xtype: 'text',
        text: variable // <- error
    }]
});

And I get that variable undefined. So my guess is that item objects can not access variables of its parent. How could I access those fields?

Thanks in advance.

1 Answer 1

2

You can't access variables in the configs, you need to do it in initComponent:

Ext.define('my.class.name', {
    extend:'Ext.grid.Panel',

    variable:'',
    constructor: function(config) {
        variable = config.field;
    },

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items:[{
                xtype: 'text',
                text: me.variable
            }]
        });

        me.callParent(arguments);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.