当forceSelection = true时,重置组合框,用户可以编辑组合框

时间:2013-11-14 04:27:30

标签: javascript extjs extjs4.1

我有一个配置'forceSelection:true'的组合框。用户可以编辑组合框,例如:键入任意文本,然后立即单击重置按钮以重置组合框,但组合框不会重置为其原始值。我怎么能解决这个问题?

以下是我描述问题的代码:

var states = Ext.create('Ext.data.Store', {

    fields: ['abbr', 'name'],

    data : [

        {"abbr":"AL", "name":"Alabama"},
        {"abbr":"AK", "name":"Alaska"},
        {"abbr":"AZ", "name":"Arizona"}
        //...
    ]
   });

   Ext.create('Ext.container.Container', {

    layout: 'hbox',

    margin: '50',

    renderTo: Ext.getBody(),

    items: [
        {
            xtype: 'combobox',
            margin: '0 10 0 0',
            fieldLabel: 'Choose State',
            forceSelection: true,
            store: states,
            queryMode: 'local',
            value: 'AL',
            displayField: 'name',
            valueField: 'abbr'

        },
        {
            xtype: 'button',
            text: 'reset',
            handler: function () {
                this.up('container').down('combobox').reset();
            }
        }
    ]
   });
   });

2 个答案:

答案 0 :(得分:1)

试试这些例子..

                Ext.onReady(function(){

                  var states = Ext.create('Ext.data.Store', {

                    fields: ['abbr', 'name'],

                    data : [

                        {"abbr":"AL", "name":"Alabama"},
                        {"abbr":"AK", "name":"Alaska"},
                        {"abbr":"AZ", "name":"Arizona"}
                        //...
                    ]
                   });

                   Ext.create('Ext.container.Container', {

                    layout: 'hbox',

                    margin: '50',

                    renderTo: Ext.getBody(),

                    items: [
                        {
                            xtype: 'combobox',
                            margin: '0 10 0 0',
                            fieldLabel: 'Choose State',
                            store: states,
                            queryMode: 'local',
                            value: 'AL',
                            displayField: 'name',
                            valueField: 'abbr'

                        },
                        {
                            xtype: 'button',
                            text: 'reset',
                            handler: function () {
                                 this.up('container').down('combobox').setValue("Alabama");
                            }
                        }
                    ]
                   });
                 });

答案 1 :(得分:1)

嗨,Plz使用这些代码更新你的按钮处理程序,即使启用了foreceSelection,它也能正常工作。

                        {
                            xtype: 'button',
                            text: 'reset',
                            handler: function () {
                                  var combo=this.up('container').down('combobox');
                                  combo.lastSelection ="Alabama";
                                  combo.setRawValue(combo.lastSelection);
                                  combo.callParent(arguments)
                            }
                        }