问题
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