单击退格键或删除按钮时从组合中取消选择项目

问题描述 投票:0回答:1

我想在可编辑区域中单击退格键或删除按钮时取消选择 extjs 多选组合框中的选定项目。我知道这在标签字段中是可能的,但我的要求是专门针对组合框的。预先感谢。

extjs combobox multi-select
1个回答
0
投票

看看带有退格键(字符 - 13)的解决方案是否适合您

Ext.onReady(function() {
var store = Ext.create('Ext.data.Store', {
    fields: ['state_id', 'state_name'],
    data: [
        {state_id: 1, state_name: 'Colorado'},
        {state_id: 2, state_name: 'Maryland'},
        {state_id: 3, state_name: 'Pennsylvania'}
    ]
});
var combo = Ext.create('Ext.form.field.ComboBox', {
    valueField: 'state_id',
    displayField: 'state_name',
    store: store,
    multiSelect: true,
    enableKeyEvents: true,
    value: [1],
    listeners: {
        keydown: function(combo, event, obj) {
            if (combo.getValue().length>0){
                var val = combo.getValue();
                val.pop();
                combo.setValue(val);
                event.preventDefault();
                event.stopPropagation();
            }
            return;
        },
    },
    renderTo: Ext.getBody()
});

});
© www.soinside.com 2019 - 2024. All rights reserved.