网格“keydown”事件无法捕获特殊键,例如箭头键或 Enter 或 Tab
我在捕获 'keydown' 事件上的特殊键时遇到问题。但是如果我使用 'keyup' 事件,一切都很好,除了我无法使用它.. 似乎某些控制捕获了该事件并停止继续处理其他事件,或者?为什么?
Ext.onReady(function () {
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' },
{ name: 'phone', type: 'string', mapping: 'phoneNumber' }
]
});
var data = {
users: [
{
id: 1,
name: 'Ed Spencer',
phoneNumber: '555 1234'
},
{
id: 2,
name: 'Abe Elias',
phoneNumber: '666 1234'
}
]
};
var myStore = new Ext.data.Store({
autoLoad: true,
storeId: 'myStore',
model: 'User',
data: data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'users'
}
}
});
var main = Ext.create('Ext.container.Viewport', {
renderTo: document.body,
layout: 'fit',
items:
[
{
xtype: 'panel',
title: 'Main Panel',
items: [
{
xtype: 'gridpanel',
id: 'myGrid',
name: 'myGrid',
title: 'My Grid',
store: 'myStore',
selModel: Ext.create('Ext.selection.CellModel', {
mode: 'SINGLE',
listeners: {
select: {
element: 'el',
fn: function (editor, object, options) {
}
}
}
}),
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners: {
edit: {
element: 'el',
fn: function (editor, object, options) {
}
}
}
})
],
flex: 1,
listeners: {
keydown: {
element: 'el',
fn: function (eventObject, htmlElement, object, options) {
var pGrid = Ext.ComponentMgr.get('myGrid');
if (eventObject.keyCode == 40) // 13, 9
{
if (pGrid.selModel.getCurrentPosition().row == pGrid.store.data.length - 1) {
pGrid.store.add({ name: '', age: '', zipcode: '' });
}
}
}
}
},
columns: [
{
xtype: 'numbercolumn',
dataIndex: 'id',
header: 'ID',
sortable: true,
width: 100,
id: 'id',
editor: {
xtype: 'numberfield'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'name',
header: 'Name',
sortable: true,
width: 100,
id: 'name',
editor: {
xtype: 'textfield'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'phone',
header: 'Phone',
sortable: true,
width: 100,
align: 'right',
id: 'phone',
editor: {
xtype: 'textfield'
}
}
]
}]
}]
});
});
有什么解决办法吗?
I have an issue with catching special keys on 'keydown' event.. but all works great if I use 'keyup' event, except I can't use it ..
Seems some control catches that event and stops proceeding for others or ? and why ?
Ext.onReady(function () {
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' },
{ name: 'phone', type: 'string', mapping: 'phoneNumber' }
]
});
var data = {
users: [
{
id: 1,
name: 'Ed Spencer',
phoneNumber: '555 1234'
},
{
id: 2,
name: 'Abe Elias',
phoneNumber: '666 1234'
}
]
};
var myStore = new Ext.data.Store({
autoLoad: true,
storeId: 'myStore',
model: 'User',
data: data,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'users'
}
}
});
var main = Ext.create('Ext.container.Viewport', {
renderTo: document.body,
layout: 'fit',
items:
[
{
xtype: 'panel',
title: 'Main Panel',
items: [
{
xtype: 'gridpanel',
id: 'myGrid',
name: 'myGrid',
title: 'My Grid',
store: 'myStore',
selModel: Ext.create('Ext.selection.CellModel', {
mode: 'SINGLE',
listeners: {
select: {
element: 'el',
fn: function (editor, object, options) {
}
}
}
}),
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners: {
edit: {
element: 'el',
fn: function (editor, object, options) {
}
}
}
})
],
flex: 1,
listeners: {
keydown: {
element: 'el',
fn: function (eventObject, htmlElement, object, options) {
var pGrid = Ext.ComponentMgr.get('myGrid');
if (eventObject.keyCode == 40) // 13, 9
{
if (pGrid.selModel.getCurrentPosition().row == pGrid.store.data.length - 1) {
pGrid.store.add({ name: '', age: '', zipcode: '' });
}
}
}
}
},
columns: [
{
xtype: 'numbercolumn',
dataIndex: 'id',
header: 'ID',
sortable: true,
width: 100,
id: 'id',
editor: {
xtype: 'numberfield'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'name',
header: 'Name',
sortable: true,
width: 100,
id: 'name',
editor: {
xtype: 'textfield'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'phone',
header: 'Phone',
sortable: true,
width: 100,
align: 'right',
id: 'phone',
editor: {
xtype: 'textfield'
}
}
]
}]
}]
});
});
Is there any solution ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是一个想法。您是否尝试过使用 KeyPress 代替/以及 KeyDown ?
Just a thought. Have you tried KeyPress instead of/as well as KeyDown?
KeyNav 是一个导航包装器,允许您可以将导航键直接绑定到函数调用。 API 文档提供了有关如何使用它的很好的示例:
http://docs.sencha.com/ext-js/4-0/#/api/Ext.util.KeyNav
KeyNav is a navigation wrapper that allows you to bind navigation keys directly to function calls. The API documentation has good examples for how to use it:
http://docs.sencha.com/ext-js/4-0/#/api/Ext.util.KeyNav