简体   繁体   English

我们可以放吗 <content> 里面 <shadow> 标签?

[英]Can we put <content> inside a <shadow> tag?

Is there a way to put something like <content select=".someClass"></content> inside a <shadow> tag in a polymer template like so: 有没有办法将<content select=".someClass"></content>放入聚合物模板的<shadow>标签中,如下所示:

<shadow>
    <content select=".someClass"></content>
</shadow>

If so how? 如果可以,怎么办? because when I try it doesn't show at all. 因为当我尝试时它根本不显示。

There's no declarative way to do this. 没有声明的方式可以做到这一点。 It is possible to do it with JavaScript by selecting an element that you know exists in the <shadow> and then using getDistributedNodes() to pull the content out of your insertion point and append it to that known element. 通过选择<shadow>中已知的元素,然后使用getDistributedNodes()将内容从插入点中拉出并将其附加到该已知元素中,可以使用JavaScript进行操作。

In Polymer you can do this pretty easily leveraging automatic node finding 在Polymer中,您可以利用自动节点查找功能轻松完成此操作

If you know that the parent element has an element in it with an id of foo you could do something like this: 如果您知道父元素中包含idfoo的元素,则可以执行以下操作:

// hacky pseudo code
// assuming you have a <content id="content"> element
var content = this.$.content.getDistributedNodes().array();
content.forEach(function(node) {
  this.$.foo.appendChild(node);
}.bind(this));

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

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