Extjs:在多选组合中选择相同的值而不删除值

时间:2015-06-19 06:16:12

标签: extjs combobox extjs5

我正在使用ext5 multiselect组合。如果我们从下拉列表中选择一个值,请说“其他”并单击“外部”以取消下拉列表。 现在,“其他”值将以组合形式显示。 再次单击下拉列表并选择相同的值“其他”,它应从其值中删除“其他”。但它再次增加了同样的价值。

Here is the image: 我的代码如下:

        xtype: 'combo',
        emptyText: 'Retail BI',
        name: 'chainRefId',
        store: Ext.create('shared.store.filter.ChainRefs'),
        displayField: 'name',
        multiSelect: true,
        valueField: 'chain_ref_id',
        listeners: {
            expand: function(){                 
                this.getStore().load();    
            },
            change: function(combo, newVal) {
                if (!combo.eventsSuspended) {
                    var storeCombo = Ext.ComponentQuery.query('combo[name=storeId]')[0];
                    storeCombo.getStore().removeAll();
                    storeCombo.setValue(null);
                    var chainCombo = Ext.ComponentQuery.query('combo[name=chainId]')[0];
                    chainCombo.getStore().removeAll();
                    chainCombo.setValue(null);                          
                }
            }
        }

有解决方案吗? 提前谢谢。

2 个答案:

答案 0 :(得分:0)

您的组合商店会在每次展开时重新加载。从技术上讲,对应于您第一次选择的值的记录在第二次存储加载时消失,因此删除逻辑不“看到”它,因此将其保留在字段中。

删除此:

expand: function(){                 
    this.getStore().load();    
}

并在商店中使用autoLoad: true

答案 1 :(得分:0)

我遇到了同样的问题。我为此提供了一个解决方法。此修复程序也适用于tagfield。

//on combo store load event
load: function () {
    // I am assuming reference to combo
    var rawVal = combo.getValue(); 
    // If combo is multiselct, getValue returns an array of selected items.
    // When combo is configured as remote, everytime it loads with new records and therefore removes the old reference.
    // Hence, do setValue to set the value again based on old reference.
    combo.setValue(rawVal);
    // Here you can see, based on old reference of selected items, the drop down will be highlighted.
}