Polymer 如何在聚合物中导入模板?

Polymer 如何在聚合物中导入模板?,polymer,Polymer,我想在独立文件中创建模板库 ./my components/templates.html <template id="overTemplate"> <div on-mouseover="{{mouseOverHandler}}">OVER</div> </template> ..... 结束 ..... 并在“我的聚合物元素”中连接此文件: <link rel="import" href="./my-components/tem

我想在独立文件中创建模板库

./my components/templates.html

<template id="overTemplate">
    <div on-mouseover="{{mouseOverHandler}}">OVER</div>
</template>
.....

结束
.....
并在“我的聚合物元素”中连接此文件:

<link rel="import" href="./my-components/templates.html">

然后使用此模板:

<template bind ref="overTemplate"></template>

怎么做?怎么样

var link = document.querySelector('link[rel=import]');
var content = link.import.querySelector('#overTemplate');
document.body.appendChild(document.importNode(content, true));
多森先生的功劳。。。


Polymer有一个名为import的助手,但据我所知,它已准备好仅导入Polymer元素。

以上内容不适用于Polymer 1.0,因为模板注释绑定不再是基于DOM修改的动态绑定。 ,目前只是权宜之计,直到聚合物团队提供这种能力,即尝试提供参考模板