查看帮助:classBinding if boolean为false [英] View helper: classBinding if boolean is false

查看:76
本文介绍了查看帮助:classBinding if boolean为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果布尔值为FALSE,我如何将类绑定到视图?

How can I bind a class to a view with the #view helper, if a boolean 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}}

我要绑定如果 controller.content.isActive 为false,则不启用作为视图的类名。

I want to bind is-not-active as a class name to the view, if controller.content.isActive is false.

我可以在视图中做一个简单的逆变器功能,但是我有一个更好的方法。

I can make an simple inverter function on the view, but I there is a better way.

推荐答案

更新:Pull请求已合并,因此您可以添加一个类 false 的类,如下所示:

UPDATE: The Pull Request has been merged, so you can add a class for a false value like this:

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

如果您不想添加类,如果值为 true ,则可以使用以下语法:

If you don't want to add a class if the value is 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 (like you already do with your inverter) and bind to this:

Handlebars

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

JavaScript p>

JavaScript:

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






我创建了一个拉请求尚未合并,但它解决了这个问题,并将解决它类似于: / p>


I've create a Pull Request which has not yet been merged but it addresses this issue and would solve it similar to this:

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

这篇关于查看帮助:classBinding if boolean为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆