2012-07-11 6 views
5

ブール値がFALSEの場合、#ビューヘルパーを使用してクラスをビューにバインドするにはどうすればよいですか?ヘルパーを表示:ブール値がfalseの場合はclassBinding

// this is working 
{{#view App.MyView controllerBinding="this" classBinding="controller.content.isActive"}} 
    <div>test</div> 
{{/view}} 

// and this is what i want: 
{{#view App.MyView controllerBinding="this" classBinding="!controller.content.isActive:is-not-active"}} 
    <div>test</div> 
{{/view}} 

controller.content.isActiveがfalseの場合、私は、ビューにクラス名としてis-not-activeバインドします。

私はビューで簡単なインバータ機能を作ることができますが、私は良い方法があります。

答えて

9

UPDATE:あなたは値がtrueであれば、クラスを追加したくない場合は

{{#view App.MyView controllerBinding="this" 
    classBinding="controller.content.isActive:is-active:is-not-active"}} 
{{/view}} 

:あなたはこのようなfalse値のためにクラスを追加することができますので、プル要求は、マージされましたあなたは既にやるように(私はビューのプロパティを作成します

{{#view App.MyView controllerBinding="this" 
    classBinding="controller.content.isActive::is-not-active"}} 
{{/view}} 

:は、次の構文を使用することができますあなたのインバーター付き)、これに特異的に結合する:私はまだマージされていないPull Requestを作成しました

App.MyView = Ember.View.extend({ 
    isNotActive: Ember.Binding.not('controller.content.isActive') 
}); 

ハンドル

{{#view App.MyView controllerBinding="this" classBinding="isNotActive"}} 
    <div>test</div> 
{{/view}} 

JavaScriptのそれはこの問題に対処し、これと同様に解決するでしょう:

{{#view App.MyView controllerBinding="this" 
    classBinding="controller.content.isActive:is-active:is-not-active"}} 
    <div>test</div> 
{{/view}} 
+0

ありがとうございました。これはまさに私が "インバータ"を意味するものです。私は今これを使用し、プルリクエストを希望します。 – Lux

関連する問題