Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 4.1 Combo - How to make select function fire When call combo.setValue

Tags:

extjs

extjs4.1

I have a combo like

        items: {  
            xtype: 'combo',
            id: 'combo',
            queryMode: 'local',                
            displayField: 'name',
            valueField: 'id',
            store: Ext.create('Ext.data.Store', {
                fields: ['id', 'name', 'mydata'],
                data: [
                  {'id': '1', 'name': 'John Smith', 'mydata': ["3", "4"]},
                  {'id': '2', 'name': 'Albert Einstein', 'mydata': ["1", "2"]}
                ]
            }),
            listeners: {
               select: function( combo, records, eOpts ) {
                    alert(records[0].get('mydata')); // records is undefined
               }
            }
        }

But when i using

    var combo = Ext.getCmp('combo');
    //combo.select("1");
    combo.setValue("1");
    combo.fireEvent('select');

Then alert(records[0].get('mydata')); // records is undefined fail. How to fix this problem thanks.
Here is my code http://jsfiddle.net/LZ8XU/

like image 482
DeLe Avatar asked Aug 07 '13 17:08

DeLe


2 Answers

For some reason, the select method of the Ext comboBox doesn't fire the select event. It seems to me from your question that you want to set a value, and manually fire the select event. If so, there are a couple more fields that are necessary to pass; specifically the comboBox itself and the selected record.

Here's an implementation that does it.

var combo = Ext.getCmp('combo');
var toselect = "Albert Einstein";

combo.select(toselect);
var record = combo.getStore().findRecord('name', toselect);
combo.fireEvent('select', combo, [record]);
like image 150
Kyle Fransham Avatar answered Nov 03 '22 18:11

Kyle Fransham


Why not listen to the change event instead?

like image 45
emolaus Avatar answered Nov 03 '22 18:11

emolaus