查看帮助程序:如果布尔值为 false,则为 classBinding [英] View helper: classBinding if boolean is false

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

问题描述

如果布尔值为 FALSE,如何使用 #view 助手将类绑定到视图?

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,我想将 is-not-active 作为类名绑定到视图.

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.

推荐答案

UPDATE:Pull Request 已合并,因此您可以为 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:

把手:

{{#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 尚未合并但它解决了这个问题,并会像这样解决它:


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

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

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