user1236125
user1236125

Reputation: 13

SENCHA TOUCH Ext.form.Select. How populate a combo with data coming from a hardcoded variable?

Saluts!!!! I have my combo, IN SENCHA TOUCH, declared as the following

Ext.regModel('modelo', {fields: ['id', 'nombre']});

aaStore = new Ext.data.Store({
    model: 'modelo',
    autoLoad: (noLoad !== true),
    autoDestroy : true,
    proxy: {
        type: 'ajax',
    url: url,
    extraParams: extraParams,
    reader: {
        type: 'array'
        }
    }
});
 bSelect = new Ext.form.Select({Ext.apply({
        label: label,
        name: name,
        store: aaStore,
        placeHolder: config.placeHolder || 'Seleccione...',
        valueField: config.valueField || 'id',
        displayField: config.displayField || 'nombre',
        useClearIcon: config.useClearIcon || true
    })

})

I am almost new to Sencha touch, and I need to populate my combo "Ext.form.Select" from data coming from a variable, I mean, I found a plain of examples loading data from a proxy, dynamically, but that's not what I need. I need to load data to my combo from a variable that is hardcoded. I mean I've built the variable, an array type variable, like this:

var varArray = [['1','2'],['3','4'],['5','6']]

and I want to charge that data to my combo bSelect ,

I've tried the following:

this.bSelect.store.loadData(varArray,false);

but, although the data has been charged, I cannot be displayed, and when I select and element of that combo, it appears like "undefined"

Please, somebody help me out. How can I load data from an array variable into my sencha touch combo?

Upvotes: 0

Views: 3457

Answers (2)

Jason Freitas
Jason Freitas

Reputation: 1585

You can add an options array to your config object. From the docs:

options : Array (Optional) An array of select options.

[
    {text: 'First Option',  value: 'first'},
    {text: 'Second Option', value: 'second'},
    {text: 'Third Option',  value: 'third'}
]

Note: option object member names should correspond with defined valueField and displayField values. This config will be ignore if a store instance is provided

Upvotes: 1

Saket Patel
Saket Patel

Reputation: 6683

Ext.regModel('modelo', {
    fields: [
        { name : 'id', type : 'string'},
        {name : 'nombre', type : 'string'}
    ]
});

aaStore = new Ext.data.Store({
    model: 'modelo',
    data : [{id : '1', nombre : '2'},{id : '3', nombre : '4'}, {id : '5', nombre : '6'}]
});

bSelect = new Ext.form.Select({
        label: label,
        name: name,
        store: aaStore,
        placeHolder: config.placeHolder || 'Seleccione...',
        valueField: config.valueField || 'id',
        displayField: config.displayField || 'nombre',
        useClearIcon: config.useClearIcon || true
    });

console.log(bSelect);

i think this should work for you

Upvotes: 1

Related Questions