在Polymer 1.0中,如何将数据绑定到元素的布尔属性? [英] In Polymer 1.0 how can I databind to a boolean property of an element?

查看:69
本文介绍了在Polymer 1.0中,如何将数据绑定到元素的布尔属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何绑定到元素的布尔属性.看来

How can I bind to a boolean property of an element. It seems this

<my-element a-property-of-type-boolean='{{someBoolean}}'></my-element>

不起作用,但是当这样暴露时,我也找不到如何绑定它:

does not Work, but I also cant find out how to bind to it when it is exposed like this:

<my-element a-property-of-type-boolean></my-element>

似乎可以选择将类型设置为Object而不是Boolean,但是我不确定这种方法的有效性

It seems an option is to set the type to Object instead of Boolean, but I am not sure how valid this approach is

谢谢:-)

推荐答案

如果在元素上放置一个属性,则其相关属性将始终为true.例如:

If you put an attribute on your element, the related property it will always be true. For example in:

<my-element a-property-of-type-boolean='false'></my-element>

a-property-of-type-boolean是真的.

因此,如果要在元素上使用布尔属性,我建议使用默认值false声明该属性,然后,如果需要将该值更改为true,则可以在其上添加属性元素.

So, if you you want to use a Boolean property on your element, I suggest to declare the property with the default value of false and then, if you need to change the value to true, you can add the attribute on you element.

您的Polymer原型:

Your Polymer prototype:

Polymer({
  is: 'my-element',
  properties: {
    aPropertyOfTypeBoolean: {
      type: Boolean,
      value: false
    }
  }
});

您的元素:

<my-element a-property-of-type-boolean></my-element>

这篇关于在Polymer 1.0中,如何将数据绑定到元素的布尔属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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