我想知道在输入聚焦时如何触发动作。
现在我在我的模板上使用它:{{view "clickinput" class="form-control" placeholder="search..." value=s action="focus"}}
这就是观点:
export default Ember.TextField.extend({
onEvent: 'focusIn',
focusIn: function() {
this.sendAction('focusIn', this, event);
}
});
这在我的控制器上:
actions: {
focus: function() {
alert('f');
}
}
但它不起作用。
我在chrome上遇到此错误:Uncaught Error: Assertion Failed: The focusIn action was triggered on the component <appkit@view:clickinput::ember438>, but the action name (function superWrapper() { var ret, sup = this.__nextSuper; this.__nextSuper = superFunc; ret = func.apply(this, arguments); this.__nextSuper = sup; return ret; }) was not a string.
为什么?
答案 0 :(得分:16)
{{input class="form-control" placeholder="search..." value=s focus-in="focus"}}
答案 1 :(得分:0)
我用你的答案作为起点,谢谢!这对我有用:
Ember stats:
DEBUG: -------------------------------
DEBUG: Ember : 1.7.1
DEBUG: Ember Data : 1.0.0-beta.11
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery : 2.1.3
DEBUG: Model Fragments : 0.2.7
DEBUG: -------------------------------
我的通用函数,我称之为functions.js
Ember.TextField.reopen({
attributeBindings: ['data-stripe'],
focusIn: function() {
return this.sendAction('focus-in');
}
});
我的控制器
actions: {
focusField: function() {
debugger;
}
}
我的手柄模板
{{input focus-in="focusField" type="tel" maxlength="20" data-stripe="number" placeholder="Card Number" value=input.number autocomplete="cc-number"}}