使用 polymer 我可以使用 <template>
- 标记在 <polymer-element>
之外使用is='auto-binding'
属性。然而,我怎样才能在 Javascript 中知道 <template>
实际上已经初始化了。我尝试监听我能想到的每一个可能的事件,并浏览了一下源代码,但似乎在任何地方都找不到任何指针,尽管我认为这一定是可能的。
如果我的意思很难理解,可以通过简单的 jsfiddle 显示问题 here ,不过我认为上面的描述应该足够了。
最佳答案
您想要监听模板绑定(bind)
事件。 this section底部提到了.
<template is="auto-binding" id="tmpl">
<input value="{{test}}">
{{test}}
</template>
<script>
var tmpl = document.querySelector('#tmpl');
tmpl.test = 123;
tmpl.addEventListener('template-bound', function() {
console.log('template bound fired!');
console.log(document.querySelector('input'));
});
</script>
我拍了a screencast on auto-binding templates其中涵盖了更多内容。
关于javascript - 使用polymer.js 的 <template> 初始化事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28369413/