简体   繁体   English

ExtJS Combo默认值返回null

[英]ExtJS Combo default value returned null

I have set up an ComboBox in my application. 我在应用程序中设置了一个ComboBox。 Combo has emptyText and default value that I have set. 组合具有emptyText和我设置的默认值。

I wish to keep '7AM' text and '7' as a default value. 我希望保留“ 7AM”文本和“ 7”作为默认值。 but when I try to submit page by selecting '7AM', then null value is returned. 但是当我尝试通过选择“ 7AM”提交页面时,则返回null值。

// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
    fields : [
        'id',
        'text'
    ],
    data: [
        {
            'id':'3',
            'text':'3AM'
        },
        {
            'id':'4',
            'text':'4AM'
        },
        {
            'id':'5',
            'text':'5AM'
        },
        {
            'id':'6',
            'text':'6AM'
        },
        {
            'id':'7',
            'text':'7AM'
        }
    ]
});

// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Choose State',
    store: states,
    queryMode: 'local',
    displayField: 'text',
    valueField: 'id',
    emptyText: '7AM',
    value: '7',
    renderTo: Ext.getBody(),
    listeners: {
        'select': function(cbo){
            alert(cbo.getValue());
        }
    }
});

Above is the test code, can you advise why null is alerted when I select 7AM ? 上面是测试代码,您能建议我选择7AM时为什么会提示null吗?

// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
    fields : ['id', 'text'],
    data: [{'id':'3','text':'3AM'}, {'id':'4','text':'4AM'}, {'id':'5','text':'5AM'},{'id':'6','text':'6AM'},{'id':'7','text':'7AM'}]
});

// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Choose State',
    store: states,
    itemId: 'combo',
    queryMode: 'local',
    displayField: 'text',
    valueField: 'id',
    //emptyText: '7AM',
    //value: '7',
    renderTo: Ext.getBody(),
    listeners: {
        'select': function(cbo){
            alert(cbo.getValue());
        },
        'afterrender': function(cbo) {
            cbo.setValue("7");
        }
    }
});

Your example seems to be OK. 您的示例似乎还可以。 So your issue must be somewhere else, not in the combo itself. 因此,您的问题必须在其他地方,而不是在组合本身中。

1- Check if there is no error in the console in your application. 1-检查应用程序的控制台中是否没有错误。

2- Check if the store is loaded when you check for it's value. 2-在检查商店的价值时检查商店是否已装入。

3- Check if there is no event changing the combo value after it is rendered. 3-检查渲染组合值后是否没有事件更改组合值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM