Digging custom tags out of Polymer element definitions

蹲街弑〆低调 提交于 2020-01-06 10:50:13

问题


Dealing with some relics of the past in our elements' implementation, we've hit a snag reaching into <template> elements externally to retrieve specific content. For example, we leave a <script id="ceci-definition"> in our elements which contains some meta data about the element. Looks like this:

<polymer-element>
  <template>
    <script id="ceci-definition">{ ... }</script>
  </template>
</polymer-element>

Later, we try to retrieve it using something ugly like this:

window.CustomElements.registry[elementName].prototype.element.impl.querySelector('template').content.querySelector('script#ceci-definition');

I'm in the process of moving those definition s to be direct children of the which encloses them, which makes reaching in for that data much easier. Like this:

<polymer-element>
  <script id="ceci-definition">{ ... }</script>
  <template>
  </template>
</polymer-element>

and slightly less ugly...

window.CustomElements.registry[elementName].prototype.element.impl.querySelector('script#ceci-definition');

My question: is there a cleaner, Polymer way to reach into the <polymer-element> tag for something?

Note: Trying not to place this meta data on the object which is passed to Polymer().


回答1:


This is exactly what core-meta is for.



来源:https://stackoverflow.com/questions/22947490/digging-custom-tags-out-of-polymer-element-definitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!