如何动态地在extjs中进行组合框多选/单选

时间:2013-06-04 05:26:52

标签: javascript extjs extjs4.1

我正在使用 ExtJs 4.1 中的组合框扩展的 Boxselect 。基于某些条件,我需要选择单个或多个。

这是我的代码

bool result;
result = getData();
if(result)
{
  Ext.getCmp("combo1").multiSelect =true
}

这不会将组合框改为多选。任何想法?

2 个答案:

答案 0 :(得分:1)

multiSelect选项更改时,您必须强制重新创建选择器。为此,您需要删除组合的属性picker

 combo.multiSelect = true;
 delete combo.picker;

完整示例:

Ext.widget('panel', {
    renderTo: Ext.getBody(),
    layout: {type: 'vbox', align: 'center'},
    margin: 10,
    defaults: {width: 200, margin: 5},
    items: [{
        xtype: 'combo',
        store: ['Foo', 'Bar', 'Baz']
    },{
        xtype: 'displayfield',
        fieldLabel: 'Multiselect is',
        value: "OFF"
    },{
        xtype: 'button',
        text: "Toggle multiselect",
        handler: function() {
            var panel = this.up(),
                combo = panel.down('combo'),
                outField = panel.down('displayfield'),
                newValue = !combo.multiSelect;
            combo.multiSelect = newValue;
            // force recreation of picker
            delete combo.picker;
            outField.setValue(newValue ? "ON" : "OFF");
        }
    }]
});

答案 1 :(得分:-2)

尝试使用Ext.apply方法。

combo = Ext.getCmp.....  
Ext.apply(combo, {multiSelect: true});