Polymer在javascript中动态地将child附加到content元素(Polymer dynamically append child to content element in javascript)
我正在构建一个聚合物元素托管框架,用户可以使用标头配置他们想要在外框内托管的项目。 例如,如果内容设置为“纸质按钮”,则主机将显示带工具栏的按钮。 我在哪里添加appendChild代码,它不适用于ready或attached事件?
<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>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?
<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函数来获取Polymer的dom并调用结果的appendChild ,并传递customElement :
Polymer.dom(this).appendChild(customElement);You can get the dom of Polymer by passing this and call the appendChild of the result, passing customElement:
Polymer.dom(this).appendChild(customElement);更多推荐
发布评论