在Polymer 1.0中,如何将数据绑定到元素的布尔属性?

编程入门 行业动态 更新时间:2024-10-21 09:49:10
本文介绍了在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中,如何将数据绑定到元素的布尔属性?

本文发布于:2023-08-02 11:41:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔   绑定   如何将   属性   元素

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!