从Polymer元素定义中挖掘自定义标签

时间:2014-04-08 20:27:58

标签: javascript polymer

在我们的元素实现中处理过去的一些遗留问题,我们遇到了从外部进入<template>元素以检索特定内容的障碍。例如,我们在元素中留下<script id="ceci-definition">,其中包含有关元素的一些元数据。看起来像这样:

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

稍后,我们尝试使用像这样丑陋的东西来检索它:

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

我正在将这些定义移动到包含它们的直接子节点的过程中,这使得更容易获得该数据。像这样:

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

稍微不那么丑......

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

我的问题:是否有一种更清晰的聚合方式可以触及<polymer-element>标记?

注意:尽量不要将此元数据放在传递给Polymer()的对象上。

1 个答案:

答案 0 :(得分:0)

这正是core-meta的用途。