2017-04-12 109 views
0

我有一個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的新手。

+0

上述解決方案僅適用於打開抽屜面板。打開時,在我看來覆蓋了菜單按鈕,因此只需單擊旁邊的按鈕即可關閉。如果你想通過菜單按鈕關閉它,你需要確保它通過'togdraw:「main」'。 – Vims

回答

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> 
相關問題