简体   繁体   English

Ember.js Handlebars绑定逻辑不对

[英]Ember.js Handlebars bindings logical not

Is there a logical not for handlebars bindings with Ember.js? 是否有合理的手柄与Ember.js绑定?

Suppose I have a ember view that I want to bind to a value 假设我有一个我想要绑定到值的余烬视图

{{Ember.Button disabledBinding="view.controller.some_value"}}

I only want the button to be disabled if some_value is false . 我只希望如果some_valuefalse禁用该按钮。 The code above makes it disabled if some_value is true . 如果some_valuetrue则上面的代码会禁用它。

One approach to fixing this would be to have a complementary computed value on the controller. 解决此问题的一种方法是在控制器上具有互补的计算值。 excuse my coffeescript 请原谅我的咖啡

opposite_some_value: (->
    if @get('some_value') == true
        return false
    else
        return true
).property 'some_value'

But this seems clunky. 但这似乎很笨拙。

Creating a property with the inverted value is the way to go. 创建具有反转值的属性是可行的方法。 You can use binding helper for this: oppositeValueBinding: Ember.Binding.not('some_value') . 您可以使用绑定帮助程序: oppositeValueBinding: Ember.Binding.not('some_value')

Also note the Ember.Button is deprecated and you should use the {{action}} helper instead. 另请注意,不推荐使用Ember.Button ,您应该使用{{action}}帮助程序。

UPDATE UPDATE

In newer versions of Ember.js, it's oppositeValue: Ember.computed.not('some_value') . 在较新版本的Ember.js中,它是oppositeValue: Ember.computed.not('some_value')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM