2

I have a form with combos in it, and I am trying to figure out an easy way of passing the combo values through to the combo widget.

Basically I am passing through an array to my form like so :

    var contentPanel = Ext.create('MyForm', {
        countryCodesForCombo: _this.countryCodesForCombo,
    });

This means the data comes through the initComponent method.

Ext.define('MyForm', {
    extend: 'Ext.form.Panel',

    initComponent : function (){

        var cCodes = this.countryCodesForCombo;

        this.callParent();
    },
    items: [
        {
            fieldLabel: 'Hi',
            xtype: 'combobox',
            name: 'land',
            displayField:'name',
            store: {
                fields: ['name'],
                data: this.countryCodesForCombo // <--- want to get country codes somehow here
            }
        }
    ]
});

However the values can't get to the item objects.

Basically my question is, how do I get values passed through the initComponent method into the items array?

1
  • Think about the order of evaluation. The whole RHS of the object needs to be evaluated before it's ever even passed to define. The class doesn't exist, let alone an instance. Commented Sep 4, 2014 at 9:26

1 Answer 1

2

Your store doesnt look right. You have to create a store object.

This will work:

Ext.define('MyForm', {
    extend: 'Ext.form.Panel',

    initComponent : function (){

        this.store = Ext.create('Ext.data.Store', {
            fields: ['name'],
            data: this.countryCodesForCombo
        });

        Ext.apply(this, {

                    items: [{

                        fieldLabel: 'Hi',
                        xtype: 'combobox',
                        queryMode: 'local',
                        name: 'land',
                        displayField:'name',
                        store: this.store                    
                    }]
        });

        this.callParent();
    },

});

Here is a fiddle link too: https://fiddle.sencha.com/#fiddle/9ru

Sign up to request clarification or add additional context in comments.

2 Comments

my store is OK. I was just wondering if there was a cleaner way of passing values to the items. Using Ext.apply(this... ) just seems a bit messy to me.
I think Ext.apply(this,{..}) is OK if you are not mixing it a lot. But i had headache too until i got used to it.

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.