Extjs combobox: hide selected value from dropdown list

后端 未结 5 1414
青春惊慌失措
青春惊慌失措 2021-02-15 14:57

I\'m using ExtJS 4 and looking for a way I can hide currently selected value from combo\'s dropdown list?

So instead of this (\"Alaska\" currently selected in combobox):

5条回答
  •  孤独总比滥情好
    2021-02-15 15:26

    I don't think you have to much options here... maybe you could do something like this:

    Ext.define('Your.company.Combo', {
        extend: 'Ext.form.field.ComboBox',
        alias: 'widget.specialcombo',
    
        /**
        * @cfg {boolean} hideActive
        * True to hide any selected record. Defaults to true.
        */
        hideActive: true,
    
        /**
        * @private {Ext.data.Model[]} hideActive
        * A Array of selected records.
        */
    
    
        initComponent: function () {
            this.selectedRecords = [];
    
            this.callParent(arguments);
    
            this.on('select', this.onSelectionChange, this);
        },
    
        /**
        * @private onChangeSelection
        * eventhandler selections
        */
        onSelectionChange: function (me, recs) {
            if(!me.hideActive)
                return;
            // write the current selected back to the store (you need to suspend autoSync if active)
            me.store.add(me.selectedRecords);
            // set the selected as new recordlist
            me.selectedRecords = recs;
            // remove the selected from the store
            me.store.remove(recs);
        }
    });
    

    That example is totally untested. But as the store is mainly bound to the BoundList which is not direct connected to the textfield this should work. You are doing a sort of caching here.

提交回复
热议问题