8

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/

DeLe
  • 2,442
  • 19
  • 88
  • 133

2 Answers2

13

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]);
Kyle Fransham
  • 1,859
  • 1
  • 19
  • 22
  • That's right, the select event is not fired automatically when calling the select() method. They should include a suppressEvent boolean parameter like they do for the button's toggle method. – Gabriel Hautclocq Oct 14 '13 at 11:50
  • @Kyle Fransham: Can you please help me with http://stackoverflow.com/questions/21521112/extjs-combobox-change-even-code-executed-on-page-load – Poonam Bhatt Feb 03 '14 at 06:51
4

Why not listen to the change event instead?

emolaus
  • 599
  • 9
  • 13
  • please help me with http://stackoverflow.com/questions/21521112/extjs-combobox-change-even-code-executed-on-page-load – Poonam Bhatt Feb 03 '14 at 06:52