0
votes

I have a combo box and I want get id of first record from server by alert(combo.store.data[0].id); But it's not working

Here is my code

        xtype: 'combo',
        value: '0',
        triggerAction:  'all',
        forceSelection: true,
        editable:       false,
        allowBlank: false,
        fieldLabel:     'example',
        mode: 'remote',

        displayField:'name',
        valueField: 'id',

        store: Ext.create('Ext.data.Store', {
        ......
        ,listeners: {
                'afterrender': function(combo){           
                    alert(combo.store.data[0].id);
                }
       }

How can i do that thanks.

2

2 Answers

3
votes

Probably you are missing something.

combo.store.getAt(0).data.id
0
votes

Try this.

Inside combobox listeners "afterrender" :

var getState = combo.getState(), //get current combobox state
    comboState = parseFloat(getState.value) - 1, 
    comboStore = combo.store;

comboStore.on("load", function(s,rs) {
    comboStore.each(function(record, key) {
        if( key ==  comboState){
            //console.log(record);
            alert(record.data.id);
        }
    });
});