简体   繁体   English

如何使用Polymer.js切换元素的隐藏/显示

[英]How to use polymer.js to toggle hidden/show of an element

I have two types of paper-card elements in the html page 我在html页面中有两种类型的纸卡元素

<paper-card done> 
<paper-card>

There is also a button 还有一个按钮

<paper-icon-button icon="menu" on-tap="_show"></paper-icon-button>

I would like to use the _show function to set the style of <paper-card done> to toggle its view state, ie, toggle display between none and block . 我想使用_show函数设置<paper-card done>的样式以切换其视图状态,即在noneblock之间切换display How to use polymer to do this? 如何使用聚合物来做到这一点? Thanks. 谢谢。

the fastest way to hide/show something in polymer is to use the "hidden" attribute with a boolean property and binding. 在聚合物中隐藏/显示某些东西的最快方法是使用带有布尔属性和绑定的“ hidden”属性。 Here is an example. 这是一个例子。

<paper-card done hidden$="[[hideDone]]"> 

The '$' before the equal is for telling polymer it's a boolean property and to handle it accordingly. 等于之前的'$'表示聚合物是布尔型属性,并进行相应处理。

Then all you have to do is a 那你要做的就是

this.set('hideDone', true)

in your '_show' function, and that should do the trick :) 在您的“ _show”函数中,那应该可以解决问题:)

To show it again, just set the property to false again, and so on. 要再次显示它,只需再次将该属性设置为false,依此类推。

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

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