如何覆盖ExtJS 4中的Ext.selection.RowModel

时间:2014-06-12 01:27:27

标签: javascript extjs extjs4 extjs4.1 extjs4.2

在ExtJS 4中,他们在网格面板上引入了空格键切换选择。我希望能够覆盖onKeyPress并禁用它。 (我不想禁用enableKeyNav)

我尝试了什么;

//This didn't work....
Ext.override('Ext.selection.RowModel', {
    onKeyPress: function(e, t) {
      console.log(e);
    }
});
//This also didn't work...
Ext.define('MyApp.selection.RowModel', {
  override: 'Ext.selection.RowModel',
  onKeyPress: function(e, t) {
    console.log(e);
  }
});

相关主题; ExtJS 4 Grid Panel - Spacebar row toggle

我要覆盖的源代码;

// Select/Deselect based on pressing Spacebar.
// Assumes a SIMPLE selectionmode style
onKeyPress: function(e, t) {
    if (e.getKey() === e.SPACE) {
        e.stopEvent();
        var me = this,
        record = me.lastFocused;

        if (record) {
            if (me.isSelected(record)) {
                me.doDeselect(record, false);
            } else {
                me.doSelect(record, true);
            }
        }
    }
},

1 个答案:

答案 0 :(得分:0)

所以似乎onKeyPress在4.2.2中不存在,这就是我所使用的。

结束了......

Ext.define('MyApp.selection.RowModel', {
  override: 'Ext.selection.RowModel',
  onKeySpace: function(e) {
    console.log(e);
  }
});

来源:http://docs.sencha.com/extjs/4.2.2/source/RowModel.html