2011-01-29 38 views
13

我尝试使用组合框上FormPanel中ExtJS的组合框,它的定义是这样的:像个普通选择

 
     xtype:   'combo', 
     name:   'Reasons', 
     store:   new Ext.data.ArrayStore({ 
     id:  0, 
     fields: [ 'myId', 'displayText' ], 
     data: [ [ 1, 'Reason 1' ], [ 2, 'Second Reason' ], [ 3, 'Something else' ] ] 
     }), 
     typeAhead:  false, 
     mode:   'local', 
     valueField:  'myId', 
     displayField: 'displayText', 
     allowBlank:  false, 
     editable:  false, 
     forceSelection: true 

我想表现得像一个普通的选择元素,当我有可编辑的假我不能重新选择,当为真(默认)我需要删除选择(通过退格或删除),以便重新选择。

还有什么我应该关闭降级组合框选择或shpuld我认为使用其他组件而不是?我很关心的是,如果我真的需要普通的选择(不是很普通 - 存储和操作选项的能力非常酷) - combox在我看来是下一级元素,我需要关闭太多功能,而且combox被渲染为带有向下箭头的输入图像什么触发所有动作...

我的问题是:ExtJS元素是什么使用HTML select标签,充当select,呈现为select?

+0

可以发布全功能呼叫分机。 Combobox – Chandu 2011-01-29 00:31:00

回答

10

诀窍在于使用triggerAction: 'all' - 当您单击向下箭头图标(触发器)时,它会强制组合下拉列表显示所有项目。

这可能是ExtJS最直观的配置选项。通过阅读文档,我们不可能弄清楚它确实做了什么。就像你说的,为了得到一个简单的组合,你必须指定一个无数的配置选项,只是为了把喜欢的东西关掉。

ExtJS家伙已经承诺在ExtJS 4中修复这个问题,但在那之前我建议你创建自己的ComboBox类,这个类是你的应用中最经常需要的配置。例如,我在我的当前项目是这样的:

/** 
* Simple combo, that just allows to choose from a list of values. 
*/ 
var StaticComboBox = Ext.extend(Ext.form.ComboBox, { 
    mode: 'local', 
    triggerAction: 'all', 
    editable: false, 
    valueField: 'value', 
    displayField: 'label', 
    /** 
    * @cfg {[[String]]} data 
    * Items in combobox as array of value-label pairs. 
    */ 
    data: [], 

    initComponent: function() { 
    this.store = new Ext.data.ArrayStore({ 
     fields: ['value', 'label'], 
     data: this.data 
    }); 
    StaticComboBox.superclass.initComponent.call(this); 
    } 
}); 

有了这样的,我可以创建只需要几行简单的组合:

new StaticComboBox({ 
    name: 'Reasons', 
    data: [ 
    [1, 'Reason 1'], 
    [2, 'Second Reason'], 
    [3, 'Something else'] 
    ] 
});