2017-04-03 40 views

回答

0

回答我自己的問題。以下是我所做的:

我發現了一個handlebars屬性insert-newline ='[functionCall]',用於過濾輸入密鑰。

1

目前我知道2種方式:

  1. 關注HTML標準

使用<form> {{input type='submit' action='submitForm'}} </form>。 請記住在submitForm中使用event.preventDefault(),否則它將重定向到窗體的動作屬性(如果沒有設置任何屬性,則刷新當前頁面)。

  • 使用的keydown/KEYUP在要觸發進入每一個表單元素事件(當然,這確實是一個壞主意,但它的工作原理):
  • Template.hbs

    {{input type='textbox' key-up='submitForm'}} 
    

    Controller.js

    export default Ember.Controller.extend({ 
        actions: { 
        submitForm(value, event) { 
         if (event.keyCode === 13) { 
         // Do something here 
         } 
        } 
        } 
    }); 
    
    相關問題