聚合物纸 - 抽屉 - 面板不接受来自儿童的切换

时间:2017-04-12 13:38:20

标签: polymer paper-elements

我在一个元素中有一个paper-drawer-panel,在子元素中有一个工具栏。在工具栏上是一个菜单按钮,应该切换抽屉面板,但它不会。如何告诉paper-drawer-panel接受来自子元素的命令?

父元素:

<dom-module id="nav-drawer">
<template>
   <paper-drawer-panel drawerFocusSelector="">
      <div drawer id="drawerbox">
         Contents of drawer panel here.
      </div>
      <div main>
         <tool-bar></tool-bar>
      </div>
   <paper-drawer-panel>
</template>
</dom-module>

子元素:

<dom-module id="tool-bar">
  <template>
    <paper-toolbar>
      <paper-icon-button icon="menu" paper-drawer-toggle></paper-icon-button>
    </paper-toolbar>
  </template>
</dom-module>

感谢您的帮助。我是Polymer的新手。

1 个答案:

答案 0 :(得分:0)

我自己找到了答案: 我更改了tool-bar元素如下,添加了attributeson-tap函数。

<dom-module id="tool-bar" attributes="togdraw">
  <template>
    <paper-toolbar>
      <paper-icon-button icon="menu" on-tap="toggleDrawer"></paper-icon-button>
    </paper-toolbar>
  </template>
<script>
.....
      toggleDrawer: function() {
        this.fire('eventFromChild',{togdraw:"drawer"});
      }
....
</script>

</dom-module>

nav-drawer我改变了相应的方式:

<dom-module id="nav-drawer">
<template>
   <paper-drawer-panel drawerFocusSelector="" selected="{{selectPanel}}">
      <div drawer id="drawerbox">
         Contents of drawer panel here.
      </div>
      <div main>
         <tool-bar></tool-bar>
      </div>
   <paper-drawer-panel>
</template>
<script>
....
  properties: {
      selectPanel: String
  },
  ready: function() {
    this.addEventListener('eventFromChild', this.toggleDrawer);
  },
  toggleDrawer: function(event,selectPanel) {
    this.selectPanel = event.detail.togdraw;
    return selectPanel;
  }
....
</script>
</dom-module>