iron-selector selected={{}} binding with iron-pages selected={{}} (Switcheroo)

旧城冷巷雨未停 提交于 2020-01-17 04:59:20

问题


So i made a custom-menu with iron-selector and put it inside on another custom element wich contains iron-pages and i can't bind the buttons of my menu with the content of the pages. Basically a Switcheroo with custom elements. Here is some code (simplified):

my-menu

<dom-module id="my-menu">
  <style>
    :host {display: inline-block;        }
  </style>    
  <template>
    <iron-selector id="menu" selected="{{menuSelected}}" attr-for-selected="name-menu">
      <div name-menu="portfolio" class="button"></div>
      <div name-menu="about" class="button"></div>
      <div name-menu="contact" class="button"></div>
    </iron-selector>
  </template>

  <script>
    Polymer({
      is: 'my-menu',
      behaviors: [Polymer.IronSelectableBehavior],
      poperties:{
        menuSelected:{
          type: String,
          value: 'portfolio'
        }
      }
    });
  </script>
</dom-module>

and my-pages

<dom-module id="my-pages">
  <style>
    :host {display: inline-block;}
  </style>

  <template>

    <my-menu menu-selected="{{pageSelected}}"></my-menu>

    <iron-pages attr-for-selected="page" selected="{{pageSelected}}"> 
      <section page="portfolio"> Some Content </section>
      <section page="about"> Some Content </section>
      <section page="contact"> Some Content </section>
    </iron-pages>
  </template>

  <script>
    Polymer({
      is: 'my-pages',
    });
  </script>
</dom-module>

Thanks for reading this! =)


回答1:


You need to add 'notify: true' to menuSelected. So that my-pages knows when my-menu modifies the value of menuSelected. Also as others mentioned, you need to fix the spelling of properties. Change it as below:

  properties:{
    menuSelected:{
      type: String,
      notify: true,
      value: 'portfolio'
    }
  }



回答2:


You can get rid of the Polymer.IronSelectableBehavior behaviour because it is a dependency loaded by iron-selector already.

You've also spelt properties incorrectly in the my-menu element: 'poperties'...



来源:https://stackoverflow.com/questions/32673783/iron-selector-selected-binding-with-iron-pages-selected-switcheroo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!