输入获得焦点时如何触发动作? [英] How to trigger an action when an input gets focus?

查看:72
本文介绍了输入获得焦点时如何触发动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当输入集中时如何触发动作。.

现在我在模板上使用它: {{查看 clickinput类= form-control placeholder = search ... value = s action = focus}}

,这就是视图:

I want to know how to trigger an action when an input gets focused..
right now I'm using this on my template: {{view "clickinput" class="form-control" placeholder="search..." value=s action="focus"}}
and this as the view:

export default Ember.TextField.extend({
  onEvent: 'focusIn',
  focusIn: function() {
    this.sendAction('focusIn', this, event);
  }
});

而这在我的控制器上:

actions: {
  focus: function() {
    alert('f');
  }
}

但是它不起作用。
我在chrome上遇到此错误:未捕获的错误:断言失败:在组件< appkit @ view:clickinput :: ember438>上触发了focusIn操作,但是操作名称(功能superWrapper (){var ret,sup = this .__ nextSuper; this .__ nextSuper = superFunc; ret = func.apply(this,arguments); this .__ nextSuper = sup; return ret;})不是字符串。

为什么?

推荐答案

原来更简单比我想象的要多。

我只需要写 {{input class = form-control placeholder = search ... value = s focus-in = focus }} 在我的模板中

It turned out to be simpler than I thought..
I just had to write {{input class="form-control" placeholder="search..." value=s focus-in="focus"}} in my template

这篇关于输入获得焦点时如何触发动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆