2014-04-16 13 views
7

Tôi muốn biết làm thế nào để kích hoạt một hành động khi một đầu vào được tập trung ..
ngay bây giờ tôi đang sử dụng này trên mẫu của tôi: {{view "clickinput" class="form-control" placeholder="search..." value=s action="focus"}}
và điều này là quan điểm:Làm cách nào để kích hoạt hành động khi đầu vào được lấy tiêu điểm?

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

và điều này trên điều khiển của tôi:

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

nhưng nó không hoạt động ..
tôi nhận được lỗi này trên chrome: Uncaught Error: Assertion Failed: The focusIn action was triggered on the component <[email protected]: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.

tại sao?

Trả lời

15

Nó bật ra được đơn giản hơn tôi nghĩ ..
Tôi chỉ phải viết {{input class="form-control" placeholder="search..." value=s focus-in="focus"}} trong mẫu của tôi

-1

tôi đã sử dụng câu trả lời của bạn như là một điểm khởi đầu để cảm ơn! Đây là những gì làm việc cho tôi:

stats

Ember:

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: ------------------------------- 

chức năng chung của tôi, tôi gọi functions.js

Ember.TextField.reopen({ 
    attributeBindings: ['data-stripe'], 
    focusIn: function() { 
    return this.sendAction('focus-in'); 
    } 
}); 

điều khiển của tôi

actions: { 
    focusField: function() { 
     debugger; 
    } 
    } 

My Handlebars template

{{input focus-in="focusField" type="tel" maxlength="20" data-stripe="number" placeholder="Card Number" value=input.number autocomplete="cc-number"}} 
Các vấn đề liên quan