开发者

Extjs ComboBox doesn't pick the correct value when setValue is called

开发者 https://www.devze.com 2023-01-18 01:40 出处:网络
I have the following code: // Part of a larger form. { xtype: \'combo\', id: \'enroller\', valueNotFoundText: \'not found\',

I have the following code:

// Part of a larger form.
{
    xtype: 'combo',
    id: 'enroller',
    valueNotFoundText: 'not found',
    triggerAction: 'all',
    mode: 'local',
    fieldLabel: 'Enroller',
    store: new Ext.data.JsonStore({
        url: url,
        root: 'data',
        autoLoad: true,
        fields: ['enrollerID', 'name', 'key']
    }),
    displayField: 'name',
    valueField: 'key',
    hiddenName: 'enrollerID',
    forceSelection: true
}
// Other area of code.
Ext.getCmp('enroller').setValue(289);

Even though I can confirm the store has a record that looks like:

{"name":"Test Enroller","enrollerID":"289开发者_JS百科","key":"289"}

The combo box displays the valueNotFoundText. How can I get the combo to load the correct record?


Finally got it working with this code. I force the combo box to load the value only after the store has loaded its values. Before it was getting set before the store loaded its values.

{
    xtype: 'combo',
    fieldLabel: 'Enroller',
    ref: 'enroller',
    store: {
        xtype: 'jsonstore',
        url: context + '/store.do',
        baseParams: { 'class': 'scheduler.Enroller' },
        autoLoad: true,
        listeners: {
            load: function() {
                me.enroller.setValue(me.enroller.getValue());
            }
        }
    },
    displayField: 'name',
    valueField: 'enrollerID',
    hiddenName: 'enrollerID',
    triggerAction: 'all'
}


Try Ext.getCmp('enroller').setValue("289");

In some cases in Ext they do a compare with === which will also do a compare on the object type ie. it needs to be a string vs an int.

0

精彩评论

暂无评论...
验证码 换一张
取 消