Search code examples
jsonextjscomboboxsencha-touch

How to set a Ext.form.ComboBox default value from JSON?


I know that this is a simple question, but I got stuck looking for a solution.

First, I got the FormPanel, that obtains data passed by JSON that looks like:

var formPanel = new Ext.FormPanel({
....
[
{name: 'country', mapping: 'country'}
]
...

Then, I populate the store with data from an external file that has a list of countries

  var countryStore = new Ext.data.SimpleStore({
    fields: ['vcountry', 'vcountrydesc'],
    data : Ext.ms.data.countries,
    id:1,
    });

What I want to do is to set a default value in a Ext.form.ComboBox, which is defined as name: 'country', precisely, I want to do something like this:

  var countryFld = new Ext.form.ComboBox({
    store: countryStore,
.....
    mode: 'local',
    forceSelection: true,
    triggerAction: 'all',
    emptyText: 'Select Country',
    value: 'country', **<---I WANT TO DO THIS, BUT TO DISPLAY A VALUE, NOT A STRING!**
   ....
    }
    });

I assume that solution is very simple, but I got stuck on it.


Solution

  • SIMPLE, very stupid of me to ask... Solution is just like for any other form

    dataIndex: 'country',
    

    instead of

    value:'country',