[英]access polymer elements attribute, inside of a polymer attribute
I am trying to access the attribute of an polymer element inside of an other polymer element 我正在尝试访问其他聚合物元素内部的聚合物元素的属性
So, when the flatter-navbar-toggle is clicked I want the flatter-navbar to know so I can change some styling based on the attribute. 所以,当单击flatter-navbar-toggle时,我希望flatter-navbar知道,因此我可以根据属性更改某些样式。
<link rel="import" href="../../bower_components/polymer/polymer.html">
<polymer-element name="flatter-navbar-toggle" on-click="{{ toggle }}" attributes="toggled">
<template>
<link rel="stylesheet" href="flatter-navbar-toggle.css"/>
<div>
<span></span>
<span></span>
<span></span>
</div>
</template>
<script>
Polymer('flatter-navbar-toggle', {
toggled: false,
toggle: function () {
this.toggled = this.toggled === true ? false : true;
}
})
</script>
</polymer-element>
<polymer-element name="flatter-navbar">
<template>
<flatter-navbar-toggle id="flatterNavbarToggle">
</flatter-navbar-toggle>
<div id="flatterNavbarBody">
<content>
</content>
</div>
</template>
<script>
Polymer('flatter-navbar', {
toggledChanged: function () {
if (this.$.flatterNavbarToggle.toggled) {
this.$.flatterNavbarBody.style.display = 'block';
} else {
this.$.flatterNavbarBody.style.display = 'none';
}
}
})
</script>
</polymer-element>
You can bind to the flatter-navbar
to the flatter-navbar-toggle
toggle
attribute like this. 您可以像这样将flatter-navbar
绑定到flatter-navbar-toggle
toggle
属性。
<polymer-element name="flatter-navbar" noscript>
<template>
<flatter-navbar-toggle toggled="{{toggled}}"></flatter-navbar-toggle>
<template if="{{toggled}}">
<div><content></content></div>
</template>
</template>
</polymer-element>
jsbin example here http://jsbin.com/pusoj/1 此处的jsbin示例http://jsbin.com/pusoj/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.