如何声明性地将伪布尔属性(如禁用/检查)绑定到布尔值? [英] How to declaratively bind pseudo-boolean attributes like disabled/checked to boolean values?

查看:92
本文介绍了如何声明性地将伪布尔属性(如禁用/检查)绑定到布尔值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在将disabledchecked之类的属性绑定到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.

这篇关于如何声明性地将伪布尔属性(如禁用/检查)绑定到布尔值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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