使用 Polymer 从元素更改自动绑定模板

Change auto-binding template from element using Polymer

<template is="dom-bind" id="app">
  <div>{{title}}</div>
  <my-element></my-element>
</template>

我可以在 my-element 中强制重绘自动绑定模板吗?

我可以获取模板,但更改它不会触发重绘:

var app = document.querySelector('#app');
app.title = 'Zaphod';

你的代码应该可以工作,除了设置 title 需要等到 polymer 准备好(即元素已经注册并准备好与之交互)。

var app = document.querySelector('#app');

document.addEventListener("WebComponentsReady", function () {
    app.title = 'Zaphod';
});