我有一个v-fire聚合物:
<script>
Polymer({
is: 'v-fire',
properties : {
onFire: {
type : String,
reflectToAttribute: true
}
},
firing: function () {
this.fire('fire');
}
})
</script>
我希望能够在我的 Polymer 元素中的任何地方使用它,以使它们触发内部函数以使它们执行特定任务,例如更新,因此在v-fire
调用firing
.
例如,我制作了一个新对象来测试:
<script>
Polymer({
is: 'fire-tester',
_updateContent: function () {
alert('I get updated');
}
});
</script>
在index.html中
…
<link rel="import" href="/components/fire-tester/fire-tester.html">
…
<body>
<fire-tester id="fire-tester"></fire-tester>
<script>
(function () {
var ft = document.getElementById('fire-tester');
// make a global v-fire Polymer
var vfire = document.createElement('v-fire');
// custom callback of the Polymer's that will include the v-fire
vfire.onFire = '_updateContent';
/**
* And here, I try to insert the v-fire in the fire-tester Polymer
*/
Polymer.dom(ft.root).insertBefore(
vfire,
Polymer.dom(ft.root).childNodes[0]
);
// the dom is pretty neat, fire-tester contains v-fire with the custom on-fire callback
// then I try to fire the event
vfire.firing(); // but nothing happen
});
</script>
它不起作用,因为我相信v-fire在插入fire-tester时不会被处理。有没有办法告诉 Polymer 处理 dom 块,就好像它是在本地 DOM 中声明的一样?