2012-02-28 6 views
2

私の意見にはEmber.TextFieldがあります。私は、アプリの特定のプロパティが変更されたときに、フィールドに注目したいと思います。コールバックをフォーカスイベントにバインドする方法を学びましたが、バインディングに基づいてフィールドのフォーカスを開始する方法はありますか?一部のプロパティの変更でぼかし/フォーカスを開始

答えて

3

私はあなたが求めていると思います。

http://jsfiddle.net/algesten/MGfAd/1/

完全性についてコード:

window.App = Ember.Application.create(); 

App.model = Ember.Object.create({ 
    someProp: 123, 
}); 

App.MyTextField = Ember.TextField.extend({ 

    value: 'foo', 

    autoFocus: function() { 
     if (App.model.someProp === "42") { 
      this.$().focus(); 
     } 
    }.observes('App.model.someProp') 

}); 
​ 

HTML:

<script type="text/x-handlebars"> 
    {{view App.MyTextField}} 
</script> 

<br/>Try changing this field to '42' and see that the focus moves. 

<script type="text/x-handlebars"> 
    {{view Ember.TextField valueBinding="App.model.someProp"}} 
</script> 
​ 
+0

パーフェクト。ありがとう! Emberはいくつかの異なる方法でバインディングに近づき、私はオプションとしてオブザーバーを完全に忘れていることがあります。 – Technocrat

関連する問題