问题描述
是否存在将disabled
或checked
之类的属性绑定到true/false属性的简便方法?像
Is there an easy way to bind attributes like disabled
or checked
to true/false properties? Something like
<button disabled="{{myBooleanProperty}}">Ok</button>
<button disabled="{{myBooleanProperty}}">Ok</button>
无法正常工作.如果myBooleanProperty为false,则设置disabled="false"
,就HTML而言,该值为 true .
doesn't work as desired. If myBooleanProperty is false, this sets disabled="false"
, which is true as far as HTML is concerned.
是否有一个过滤器表达式可以提示绑定分析器,如果值为false,则应完全删除该属性?
Is there a filter expression that can hint to the binding parser that the attribute should be completely removed if the value is false?
推荐答案
请参阅条件属性: http://www.polymer-project.org/docs/polymer/binding- types.html#conditional-attributes
示例:
<button disabled?="{{myBooleanProperty}}">Ok</button>
将根据myBooleanProperty
的真实性来切换disabled
.
will toggle disabled
depending on the truthiness of myBooleanProperty
.
这篇关于如何声明性地将伪布尔属性(如禁用/检查)绑定到布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!