如何将铁选择器与铁页链接?

时间:2016-10-27 20:36:23

标签: html css polymer polymer-1.0

我最近一直在和Polymer合作,我在纸质抽屉里放了一个装满纸质图标的铁选择器,用于导航。但出于某种原因,我无法将它们链接起来:

<iron-selector selected="[[page]]" attr-for-selected="name">
    <paper-icon-item name="home">
        <iron-icon icon="icons:home" item-icon></iron-icon> Home
    </paper-icon-item>
    <paper-icon-item name="account">
        <iron-icon icon="social:person" item-icon></iron-icon> Account
    </paper-icon-item>
    <paper-icon-item name="news">
        <iron-icon icon="icons:chrome-reader-mode" item-icon></iron-icon> News
    </paper-icon-item>
    <paper-icon-item name="downloads">
                    <iron-icon icon="icons:cloud-download" item-icon></iron-icon> Downloads
    </paper-icon-item>
    <paper-icon-item name="contact">
                    <iron-icon icon="icons:mail" item-icon></iron-icon> Contact
    </paper-icon-item>
</iron-selector>

然后是铁页:

<iron-pages selected="[[page]]" attr-for-selected="name">
    <section name="home"> <h1>Home</h1> </section>
    <section name="account"> <h1>Account</h1> </section>
    <section name="news"> <h1>News</h1> </section>
    <section name="downloads"> <h1>Downloads</h1> </section>
    <section name="contact"> <h1>Contact</h1> </section>
</iron-pages>

2 个答案:

答案 0 :(得分:3)

方括号用于单向数据绑定,因此更改为&#34; page&#34;铁选择器制造的传播方式无法传播。尝试更改选择器中的绑定类型:

<iron-selector selected="{{page}}" attr-for-selected="name">

这应该允许更改传播到铁页。

答案 1 :(得分:0)

当我将代码更改为:

时,它对我有用
    <iron-selector selected="{{pages}}" attr-for-selected="name">
      <paper-icon-item name="home">
        <iron-icon icon="icons:home" item-icon></iron-icon> Home
      </paper-icon-item>
      <paper-icon-item name="account">
        <iron-icon icon="social:person" item-icon></iron-icon> Account
      </paper-icon-item>
      <paper-icon-item name="news">
        <iron-icon icon="icons:chrome-reader-mode" item-icon></iron-icon> News
      </paper-icon-item>
      <paper-icon-item name="downloads">
        <iron-icon icon="icons:cloud-download" item-icon></iron-icon> Downloads
      </paper-icon-item>
      <paper-icon-item name="contact">
        <iron-icon icon="icons:mail" item-icon></iron-icon> Contact
      </paper-icon-item>
    </iron-selector>

    <iron-pages selected="[[pages]]" attr-for-selected="name">
      <section name="home"> <h1>Homes</h1> </section>
      <section name="account"> <h1>Account</h1> </section>
      <section name="news"> <h1>News</h1> </section>
      <section name="downloads"> <h1>Downloads</h1> </section>
      <section name="contact"> <h1>Contact</h1> </section>
    </iron-pages>

不同之处在于铁选择器中的[[pages]]和{{pages}}。