简体   繁体   English

Polymer在javascript中动态地将child附加到content元素

[英]Polymer dynamically append child to content element in javascript

I am building a polymer element hosting frame, where the user can configure what item they want to be hosted inside the outerframe with header. 我正在构建一个聚合物元素托管框架,用户可以使用标头配置他们想要在外框内托管的项目。 For instance if the content is set to 'paper-button' the host will display the button with toolbar. 例如,如果内容设置为“纸质按钮”,则主机将显示带工具栏的按钮。 Where do I add the appendChild code, it doesn't work on ready or attached event? 我在哪里添加appendChild代码,它不适用于readyattached事件?

<dom-module id="element-host">
    <template>
        <paper-header-panel>
            <paper-toolbar>Header</paper-toolbar>
            <content id="content"></content>
        </paper-header-panel>
    </template>
    <script>
        Polymer({
            is: 'element-host',
            properties: {
                content : {
                    type: string
                }
            },
            attached: function(renderer) {
                var customElement = document.createElement(this.content);
                this.$.content.appendChild(customElement);
            }
        });
    </script>
</dom-module>

你可以通过传递this来获得Polymerdom并调用结果的appendChild ,传递customElement

Polymer.dom(this).appendChild(customElement);

Check out Polymer's selector . 查看Polymer的选择器 For locating dynamically-created nodes in your element's local DOM, use the $$ method: 要在元素的本地DOM中定位动态创建的节点,请使用$$方法:

this.$$(selector) 此。$$(选择器)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM