Polymer在javascript中动态地将child附加到content元素(Polymer dynamically append child to content element in java

编程入门 行业动态 更新时间:2024-10-21 10:34:00
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);

更多推荐

本文发布于:2023-07-08 20:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080246.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   动态   child   javascript   Polymer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!