View helper: classBinding if boolean false

How to associate a class with a view using the #view helper if the boolean value is FALSE?

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

I want to bind is-not-activeas a class name to the view if controller.content.isActivefalse.

I can make a simple inverter function in a view, but I have a better way.

+5
source share
1 answer

UPDATE : The Pull query has been merged, so you can add a class for the value falseas follows:

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

If you do not want to add a class, if a value true, you can use the following syntax:

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

I would create a property on the view (for example, you already did with your inverter) and attached to this:

Rudders

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

Javascript

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

Pull Request, , , :

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

All Articles