mys*_*boy 3 javascript extjs enter keyboard-events
嗨我有下面的代码,我的输入事件永远不会触发,任何帮助将不胜感激.
items: [{
xtype: 'textfield',
id: 'idhere',
name: 'namehere',
fieldLabel: 'lablehere:',
width: 500,
handler: {
key:13,
fn : function () {
if (e.getKey() == e.ENTER) {
alert("You pressed an enter button in text field.");
}
}
}
},{
xtype: 'button',
text: 'texttodisplay',
handler: function() {
//my function.
}
}]
Run Code Online (Sandbox Code Playgroud)
我实际上通过使用:
listeners: {
specialkey: function (f,e) {
if (e.getKey() == e.ENTER) {
loadData();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定为什么Sencha从未包含Ext.ux.form.SearchField在API文档中,但该组件已包含在我使用的框架的所有版本中.它设置为触发a submit和cancel事件,并包括附加到该字段的相应搜索和取消按钮.
您可以在以下框架文件中找到它: [extjs-root]\examples\ux\form\SearchField.js
我建议使用该组件,而不是尝试创建自己的搜索字段.我通常会覆盖默认搜索功能以满足我自己的需求,但是有一些我不需要的场景.
如果在组件JS的顶部添加一个requires语句,则可以像创建任何其他(非UX)组件一样创建它:
例如:
要求声明:
Ext.define('MyApp.view.SomeComponent', {
extend: 'Ext.grid.Panel',
alias: 'widget.mycomponent',
requires: [
'Ext.ux.form.SearchField'
],
...
Run Code Online (Sandbox Code Playgroud)
在面板底部工具栏中创建搜索字段:
bbar: {
items: [{
text: 'A Button'
}, {
text: 'Another Button'
}, '-', {
xtype: 'searchfield', // <- can use this xtype with requires stmt
itemId: 'search',
width: 250,
emptyText: 'Enter first and last name to search...'
}]
},
...
Run Code Online (Sandbox Code Playgroud)
如果您在使用require语句时遇到问题,您也可以像这样创建它:
var search = Ext.create('Ext.ux.form.SearchField', {
itemId: 'search',
width: 250,
emptyText: 'Enter first and last name to search...'
});
Run Code Online (Sandbox Code Playgroud)