如果布尔值为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}}
Run Code Online (Sandbox Code Playgroud)
我想绑定is-not-active
为视图的类名,如果controller.content.isActive
是false.
我可以在视图上做一个简单的逆变器功能,但我有一个更好的方法.
更新:Pull请求已合并,因此您可以为这样的false
值添加一个类:
{{#view App.MyView controllerBinding="this"
classBinding="controller.content.isActive:is-active:is-not-active"}}
{{/view}}
Run Code Online (Sandbox Code Playgroud)
如果您不想在值为的情况下添加类,则true
可以使用以下语法:
{{#view App.MyView controllerBinding="this"
classBinding="controller.content.isActive::is-not-active"}}
{{/view}}
Run Code Online (Sandbox Code Playgroud)
我会在视图上创建一个属性(就像你已经使用逆变器一样)并绑定到这个:
把手:
{{#view App.MyView controllerBinding="this" classBinding="isNotActive"}}
<div>test</div>
{{/view}}
Run Code Online (Sandbox Code Playgroud)
JavaScript:
App.MyView = Ember.View.extend({
isNotActive: Ember.Binding.not('controller.content.isActive')
});
Run Code Online (Sandbox Code Playgroud)
我创建了一个尚未合并的Pull请求,但它解决了这个问题,并将解决类似这样的问题:
{{#view App.MyView controllerBinding="this"
classBinding="controller.content.isActive:is-active:is-not-active"}}
<div>test</div>
{{/view}}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1484 次 |
最近记录: |