2013-09-30 31 views
1

我需要通過使用onKeyPress和onKeyDown事件中的某些函數將輸入值轉換爲unicode值。Emberjs輸入TextField值Unicode轉換

如何在TextField的Ember.js中創建視圖?

例如:在Javascript

<input name="comment" charset="utf-8" type="text" onKeyPress="javascript:convertThis(event)" onKeyDown="toggleKBMode(event)" /> 

回答

1

最簡單的方法來創建自己的輸入文本擴展Ember.TextField

App.MyTextField = Ember.TextField.extend({ 
    attributeBindings: ['charset'], 
    charset: 'utf-8', 
    keyPress: function(evt) { 
     console.log('keyPress', evt); 
    }, 
    keyDown: function(evt) {   
     console.log('keyDown', evt); 
    } 
}); 

attributeBindings會說什麼是使用像HTML你App.MyTextField的屬性屬性,在你的情況下字符集:attributeBindings: ['charset']。要獲得keyPresskeyDown事件,只需聲明您的各自功能。它將收到一個jQuery.Event實例。

這是該樣品小提琴http://jsfiddle.net/marciojunior/cEAhN/

我希望它能幫助

+0

非常感謝[馬爾西奧 - 羅德里格斯 - 科雷亞 - 初中(http://stackoverflow.com/users/1846480/marcio -rodrigues-correa-junior):) – TamilG