Polymer 1.0: iron-pages not switching pages with children events

大城市里の小女人 提交于 2019-12-04 17:06:26

A quick hack to solve this particular problem is to intercept the child event on the parent node, but not let it call the method to switch pages, instead, call the method asynchronous. Below is the working code for the parent node:

<dom-module is="parent-comm">
    <template>
        <iron-pages selected="0">
            <child-comm on-taped-child="asyncSwitchPages"></child-comm>
            <child-comm2 on-taped-child="asyncSwitchPages"></child-comm2>
        </iron-pages>
    </template>
</dom-module>
<script>
 Polymer({
     is: "parent-comm",
     switchPages: function() {
         this.pages.selectNext();
     },
     asyncSwitchPages: function(e) {
         this.async(this.switchPages);
     },
     ready: function() {
         this.pages = document.querySelector('iron-pages');
     }
 });
</script>

Note: I'd love to hear "why" I have to do it, so I'll just leave this answer not accepted.

I think you need to listen for the custom event. Try adding the below to parent's ready function.

this.addEventListener('taped-child', function(e) { this.switchPages(); });

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