5

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

// 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}}

falseis-not-activeの場合、クラス名としてビューにバインドしたいと思います。controller.content.isActive

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

4

1 に答える 1

9

UPDATEfalse : プル リクエストがマージされたため、次のような値のクラスを追加できます。

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

値が の場合にクラスを追加したくない場合はtrue、次の構文を使用できます。

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

ビューにプロパティを作成し (インバーターで既に行っているように)、これにバインドします。

ハンドルバー:

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

JavaScript :

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

まだマージされていないプル リクエストを作成しましたが、この問題に対処し、次のように解決します。

{{#view App.MyView controllerBinding="this"
   classBinding="controller.content.isActive:is-active:is-not-active"}}
    <div>test</div>
{{/view}}
于 2012-07-11T09:40:58.810 に答える