简体   繁体   English

尝试通过扩展元素填充Polymer Element的<content> </ content>

[英]Trying to populate a Polymer Element's <content></content> through an extended element

I have two elements: one is a <drop-down> element, the other is a <populated-drop-down> element. 我有两个元素:一个是<drop-down>元素,另一个是<populated-drop-down>元素。 populated-drop-down extends drop-down , but, as you may have guessed, tries to pre-populate it with some options. populated-drop-down extends drop-down ,但是,正如您可能已经猜到的那样,尝试使用一些选项预先填充它。 The assumption was that I could simply put HTML inside the <shadow></shadow> tag, but this does not work: 假设我可以简单地将HTML放在<shadow></shadow>标记内,但这不起作用:

<polymer-element name="drop-down" noscript attributes="label">
  <template>
    <style>
      :host{display:inline-block;border:1px solid;padding:1rem}
      #content{position:absolute}
      #drop, #content {display:none}
      #drop:checked + #content {display:block}
    </style>
    <label for="drop">{{label}}</label>
    <input type="checkbox" id="drop">
    <div id="content"><content></content></div>
  </template>
</polymer-element>


<polymer-element name="pop-drop-down" extends="drop-down" noscript>
  <template>
    <shadow>
      <ul>
         <li>Option1</li>
         <li>Option2</li>
         <li>Option3</li>
         <li>Option4</li>
         <li>Option5</li>
      </ul>
    </shadow>
  </template>
</polymer-element>


<drop-down label="Working DropDown">
      <ul>
         <li>Option1</li>
         <li>Option2</li>
         <li>Option3</li>
         <li>Option4</li>
         <li>Option5</li>
      </ul>
</drop-down>

<pop-drop-down label="Not working pre-populated dropdown">
</pop-drop-down>

( Code also available code on JSBin .) 代码也可用JSBin上的代码 。)

It seems I am able to wrap additional tags around <shadow></shadow> but not place any inside of <shadow></shadow> 看来我能够环绕其他标记<shadow></shadow> ,但不得将任何内部<shadow></shadow>

IIRC, this was supported for a brief period of time in the Shadow DOM spec and Chrome's implementation. IIRC,这在Shadow DOM规范和Chrome的实现中得到了短暂的支持。 However, it was removed due to implementation concerns. 但是,由于实施问题,它已被删除。

Most of the developer community wants this feature, but the browser implementors were concerned about creating a performance problem, so it was left out of the most recent spec. 大多数开发人员社区都想要这个功能,但浏览器实现者担心会产生性能问题,所以它被排除在最新的规范之外。

I suspect this will be a feature of ShadowDOM before long, but technically the jury is still out. 我怀疑这不久就会成为ShadowDOM的一个功能,但从技术上来说,陪审团仍然没有。

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

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