【发布时间】:2026-01-07 19:40:01
【问题描述】:
我有一个 Sencha Touch 代码库,我希望能够使用“Enter”键将初始登录提交到应用程序,而不必单击桌面上的按钮。这是我的Login 观点:
Ext.define('App.view.Login', {
extend: 'Ext.form.Panel',
alias: 'widget.login',
requires:[
'Ext.form.FieldSet',
'Ext.field.Email',
'Ext.field.Password'
],
config: {
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'App'
},
{
xtype: 'fieldset',
margin: '.5em .5em 1.5em',
title: 'Login',
items: [
{
xtype: 'emailfield',
name: 'email',
placeHolder: 'email@example.com',
required: true
},
{
xtype: 'passwordfield',
name: 'password',
placeHolder: 'password',
required: true,
}
]
},
{
xtype: 'container',
layout: {
type: 'vbox'
},
margin: '10px',
items:[
{
xtype: 'button',
margin: '10px',
itemId: 'login',
text: 'Login'
}
]
}
]
}
});
这是我的Login 控制器:
Ext.define("App.controller.Login", {
extend: "Ext.app.Controller",
config: {
views: ["Login", "user.Home"],
stores: ["LoginInstance"],
refs: {
password: 'passwordfield[name="password"]',
login: {
autoCreate: true,
selector: "login",
xtype: "login"
}
},
control: {
password: {
keyup: function(field, e) {
if(e.event.keyCode === 13) {
console.log('Do login');
this.onLoginTap();
}
}
},
"login #login": {
tap: "onLoginTap"
},
// ...
}
},
onLoginTap: function() { ... } // do the login
但是,这似乎没有做任何事情(也就是说,即使console.log 也不会出现在控制台中!)。有没有人对我可能做错了什么有建议?
【问题讨论】:
-
看起来可能是范围问题...
-
抱歉,我修正了我的格式。
onLoginTap在Ext.define块内正确定义,而不是在其外。你指的是这个还是别的什么?
标签: javascript extjs sencha-touch sencha-touch-2 dom-events