从聚合物元素定义中挖掘自定义标签 [英] Digging custom tags out of Polymer element definitions
问题描述
在元素的实现中处理过去的一些遗物,我们遇到了一个障碍,即从外部进入<template>
元素以检索特定内容.例如,我们在元素中保留<script id="ceci-definition">
,其中包含有关该元素的一些元数据.看起来像这样:
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');
我正在将这些定义s移为包围它们的的直接子代,这使得获取该数据变得更加容易.像这样:
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>
丑陋的事...
window.CustomElements.registry[elementName].prototype.element.impl.querySelector('script#ceci-definition');
我的问题:有没有一种更清洁的Polymer方法可以触及<polymer-element>
标签?
My question: is there a cleaner, Polymer way to reach into the <polymer-element>
tag for something?
注意:尽量不要将此元数据放在传递给Polymer()
的对象上.
Note: Trying not to place this meta data on the object which is passed to Polymer()
.
推荐答案
这正是 core-meta 是.
这篇关于从聚合物元素定义中挖掘自定义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!