简体   繁体   English

Ember.js地图操作keyUp事件

[英]Ember.js map action keyUp event

I'm trying out Ember.js but I'm stuck when using actions. 我正在尝试Ember.js,但在使用操作时却卡住了。

If I use the following: 如果我使用以下内容:

<button {{action "test"}}>Test</button>

And create a controller: 并创建一个控制器:

App.NewController = Ember.ArrayController.extend({
    actions: {
        test: function() {
            console.log("test");
        },
    }
});

Then everything works fine and I can see test in my log. 然后,一切正常,我可以在日志中看到test However, when I try the following: 但是,当我尝试以下操作时:

<input type="text" {{action "test2" on="keyUp"}} />

And define the test2 action in a similar way: 并以类似的方式定义test2动作:

App.NewController = Ember.ArrayController.extend({
    actions: {
        test: function() {
            console.log("test");
        },
        test2: function() {
            console.log("test2");
        }
    }
});

Then it doesn't seem to work. 然后它似乎不起作用。 My test button is working, but the keyup event handler is not fired as I expected after reading the documentation . 我的测试按钮可以正常工作,但是在阅读文档后,没有触发keyup事件处理程序。

That's really weird, I'll keep looking into it, but you could just use the input helper and observe the value, additionally you could extend the textfield and get the keyup there if you care about which key they are pressing. 真的很奇怪,我会继续研究,但是您可以只使用输入帮助器并观察其值,此外,如果您关心它们所按下的键,则可以扩展文本字段并在那里获取键。

http://emberjs.jsbin.com/EBoLEZe/1/edit http://emberjs.jsbin.com/EBoLEZe/1/edit

{{input value=name}}

  postKey: function(){
    console.log(this.get('name'));  
  }.observes('name')

See also: KeyPress event not working as expected in Ember 另请参阅: KeyPress事件无法在Ember中按预期方式工作

It looks like there is a bug (or at least very odd behavior) affecting the ability to use actions with keyboard events. 似乎有一个错误(或至少是非常奇怪的行为)影响了对键盘事件使用操作的能力。 Normally, actions handlers for non-keyboard events (like the default "click" event) don't work when modifier keys are pressed. 通常,按下修改键时,非键盘事件(例如默认的“ click”事件)的动作处理程序将不起作用。 In your code, if you add allowedKeys="any" to your action helper, then your handler will get invoked. 在代码中,如果将allowedKeys="any"添加到动作帮助器,则将调用处理程序。

Fiddle: http://emberjs.jsbin.com/oyEpImI/2/edit?html,js,output 小提琴: http ://emberjs.jsbin.com/oyEpImI/2/edit?html, js,输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM