ExtJS 4 如何在使用 MVC 时正确为窗口创建 KeyMap

发布于 2024-12-17 19:47:04 字数 642 浏览 3 评论 0 原文

我有一个简单的 ExtJS 应用程序,它是 MVC 风格编写的(我的大部分信息来自 此处)。

我的应用程序创建一个视口,并有一个带有表单、一些字段和一个按钮的视图。

该应用程序有一个具有“loginButtonClick”功能的控制器,并且该控制器通过以下方式监视单击事件:

this.control({
 'loginwindow button[action=save]': {
   click: this.loginButtonClick
 }
}

效果很好,但是现在当显示登录窗口时,我希望回车键也执行loginButtonClick方法。

我已经尝试过各种各样的事情,但我遇到的基本问题是在哪里放置用于创建键盘映射的代码,以及如何将其绑定到正确的实例,

例如,如果我在控制器中创建键盘映射(这是我的偏好)。 ,我需要得到该控制器的特定视图实例(我可能会打开多个相同类型的窗口),

那么,您如何从控制器内为其视图(窗口)创建键映射(或?),调用本地方法(此)。 .loginButtonClick) 当按下回车键时?

I have a simple ExtJS application that is written MVC style (much of my information from here).

My application creates a viewport, and has a view with a form, some fields and a button.

The application has a controller with a 'loginButtonClick" function, and the controller watches the click event with a:

this.control({
 'loginwindow button[action=save]': {
   click: this.loginButtonClick
 }
}

That works great, but now when the login window is showing, I want the enter key to also execute the loginButtonClick method.

I have tried all kinds of things, but the basic issue I am having is WHERE to put the code for creating the keymap, and how to bind it to the proper instances.

For example, if I create the keymap in the controller (which is my preference), I need to get the specific view instance for that controller (I might have multiple windows open of the same kind).

So, How would you create a key map (or?) from within a controller for it's view (window), calling a local method (this.loginButtonClick) when the enter key is pressed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生生漫 2024-12-24 19:47:04

您可以做的是将初始化 keyMap 的代码绑定到登录窗口 afterrender 事件,如下所示:

this.control{(
   'loginwindow' : {
      afterrender: this.initializeKeyMap
 }

然后创建一个设置 keyNav 的函数:

initializeKeyMap: function(window, options) {
   this.keyNav = Ext.create('Ext.util.KeyNav', window.el, {
         enter: this.loginButtonClick,
         scope: this
   });           
}

现在,当加载对话框时,如果用户按 Enter 键,它应该执行您的函数。

What you can do is bind the code that initializes the keyMap to the login window afterrender event like this:

this.control{(
   'loginwindow' : {
      afterrender: this.initializeKeyMap
 }

Then make a function that sets up the keyNav:

initializeKeyMap: function(window, options) {
   this.keyNav = Ext.create('Ext.util.KeyNav', window.el, {
         enter: this.loginButtonClick,
         scope: this
   });           
}

Now when the dialog is loaded if the user presses the Enter key, it should execute your function.

洛阳烟雨空心柳 2024-12-24 19:47:04

您可以在窗口渲染事件中设置所有这些内容。因此,当它呈现时,您为输入键添加一个事件侦听器,并在您以编程方式调用的处理程序中单击登录按钮。

You could setup all these things on your window render event. So when it is rendered you add an eventlistener for the enter key, and in the handler you call programatically click on the login button.

我最亲爱的 2024-12-24 19:47:04

您可以通过将以下侦听器添加到表单中的文本/密码字段来实现此目的,

listeners: {
    specialkey: function(field, e){
        if (e.getKey() == e.ENTER) {
            var form = this.up('form').getForm();
            submitLoginForm(form);
        }
    }
}

这里“form”是您的表单,“submitLoginForm”是在表单提交时调用的函数,我猜在您的情况下是loginButtonClick。

希望这有帮助。

You can achieve this by adding the following listeners to your text/password fields in the form

listeners: {
    specialkey: function(field, e){
        if (e.getKey() == e.ENTER) {
            var form = this.up('form').getForm();
            submitLoginForm(form);
        }
    }
}

Here 'form' is your form and 'submitLoginForm' is the function called at form submit which I guess is loginButtonClick in your case.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文