1

我必须为表单创建一个自定义绑定列表,当它具有单选并且不取消选择时它可以正常工作。如何告诉绑定列表进行取消选择和多选?

不工作:

var mode = this.multiselect ? 'MULTI' : 'SINGLE';
var sm = bl.getSelectionModel();  // TODO 
sm.setSelectionMode(mode);
sm.allowDeselect = this.deselect;

不起作用(这是在扩展的 FieldContainer 中):

var bl = Ext.create('Ext.view.BoundList', {
    multiSelect: this.multiselect,
    deselect: this.deselect,
    //...
4

2 回答 2

1

不确定您要达到什么行为。多模式默认允许取消选择,并且在这种情况下,allowDeselect 配置选项不适用。这是来自 Ext.selection.Model 文档的引用:

允许取消选择:布尔值

允许用户取消选择 DataView、List 或 Grid 中的记录。仅在模式为“SINGLE”时适用。

于 2013-05-22T16:57:34.863 回答
1

如果我理解正确,您希望能够通过在多选中单击来取消选择唯一选定的记录。

试试这个代码:

// Allow deselecting the only selected record in MULTI mode with a simple click.
// Note that this will only happen when allowdeselect is true
Ext.override( Ext.selection.Model, {
    selectWithEvent: function(record, e, keepExisting) {
        var me = this;

        switch (me.selectionMode) {
            case 'MULTI':
                if (e.ctrlKey && me.isSelected(record)) {
                    me.doDeselect(record, false);
                } else if (e.shiftKey && me.lastFocused) {
                    me.selectRange(me.lastFocused, record, e.ctrlKey);
                } else if (e.ctrlKey) {
                    me.doSelect(record, true, false);
                // Mod Start
                } else if (me.isSelected(record) && !e.shiftKey && !e.ctrlKey && me.selected.getCount() == 1 && me.allowDeselect) {
                    me.doDeselect(record, false);                    
                // Mod End                        
                } else if (me.isSelected(record) && !e.shiftKey && !e.ctrlKey && me.selected.getCount() > 1) {
                    me.doSelect(record, keepExisting, false);
                } else {
                    me.doSelect(record, false);
                }
                break;
            case 'SIMPLE':
                if (me.isSelected(record)) {
                    me.doDeselect(record);
                } else {
                    me.doSelect(record, true);
                }
                break;
            case 'SINGLE':
                // if allowDeselect is on and this record isSelected, deselect it
                if (me.allowDeselect && me.isSelected(record)) {
                    me.doDeselect(record);
                // select the record and do NOT maintain existing selections
                } else {
                    me.doSelect(record, false);
                }
                break;
        }
    },
});
于 2013-07-24T12:36:41.223 回答