如何在Polymer 1.0中创建新模板实例?

如何在Polymer 1.0中创建新模板实例?,polymer,polymer-1.0,Polymer,Polymer 1.0,在Polymer 0.5中,我使用templateElement.createInstance(dataToBind)创建模板的新实例,并将数据对象绑定到新实例: var instance = templateElement.createInstance(dataToBind); container.appendChild(instance); 在Polymer.Base中,我找到了instanceTemplate函数来创建模板的新实例,但该函数不将数据绑定到实例。 在Polymer 1.0中

在Polymer 0.5中,我使用templateElement.createInstance(dataToBind)创建模板的新实例,并将数据对象绑定到新实例:

var instance = templateElement.createInstance(dataToBind);
container.appendChild(instance);
在Polymer.Base中,我找到了instanceTemplate函数来创建模板的新实例,但该函数不将数据绑定到实例。
在Polymer 1.0中有没有实现这一点的方法?

如果您定义这样的模板:

<template is="dom-template">
  <h2>{{name}}</h2>
  <h3>...lives<h3>
</template>
<script>
  // construct the anonymous presenter
  var instance = templateInstance.stamp();
  // the data model lives on the presenter
  instance.name = 'Instance';
  // the nodes are available in `root`
  document.body.appendChild(instance.root);
</script>

{{name}}
…生活
您可以生成如下所示的实例:

<template is="dom-template">
  <h2>{{name}}</h2>
  <h3>...lives<h3>
</template>
<script>
  // construct the anonymous presenter
  var instance = templateInstance.stamp();
  // the data model lives on the presenter
  instance.name = 'Instance';
  // the nodes are available in `root`
  document.body.appendChild(instance.root);
</script>

//构造匿名演示者
var instance=templateInstance.stamp();
//数据模型位于演示者上
instance.name='instance';
//这些节点在“根目录”中可用`
document.body.appendChild(instance.root);
这或多或少是当您实例化聚合元素时发生的情况,但演示者是您元素的实例(而不是匿名对象)