在Meteor中调用事件处理程序

在Meteor中调用事件处理程序,meteor,Meteor,我有这个模板: <template name='foo'> <button id='hello'>Click me</button> </template> 现在的问题是,在替换呈现的原始按钮后,警报不再发出警报,在替换dom中的原始文档后,如何重新应用警报?您需要使用Meteor插入任何dom。使用UI.insert逻辑 首先,您需要使元素成为单独的模板或ui组件: <template name="button"> <

我有这个模板:

<template name='foo'>
<button id='hello'>Click me</button>
</template>

现在的问题是,在替换呈现的原始按钮后,警报不再发出警报,在替换dom中的原始文档后,如何重新应用警报?

您需要使用Meteor插入任何dom。使用UI.insert逻辑

首先,您需要使元素成为单独的模板或ui组件:

<template name="button">
    <button id='hello'>Click me</button>
</template>

<template name="foo">
    {{>button}}
</template>

其中dom区域是指示要将其放置在何处的内容。您可以使用模板呈现回调(this.firstNode)中返回的
firstNode
值来模拟上面代码中
replaceWith
给出的相同区域。

感谢您的想法,我没有完全遵循您的解决方案,但它确实帮助了我。
<template name="button">
    <button id='hello'>Click me</button>
</template>

<template name="foo">
    {{>button}}
</template>
$('#hello').remove();
UI.insert(UI.render("button"), [dom area of where to insert it]);