0

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

这是我的代码

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

这不会将组合框更改为多选。有什么想法吗?

4

2 回答 2

1

You have to force the recreation of the picker when the multiSelectoption change. 为此,您需要删除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");
        }
    }]
});
于 2013-06-04T06:31:01.690 回答
-2

尝试使用 Ext.apply 方法。

combo = Ext.getCmp.....  
Ext.apply(combo, {multiSelect: true});
于 2013-06-04T05:51:41.710 回答