我知道Template.onRendered,但当实际上下文更新时,我需要销毁和设置一些作用于dom的插件。
所以说我有内容模板,我需要类似于以下的东西:
Template.content.onBeforeChange(function () {
$(".editor").editable("destroy");
});
Template.content.onAfterChange(function () {
$(".editor").editable();
});
目前有什么方法可以用现有的Templateapi实现这一点吗?
您应该能够通过查看以下currentData来检测模板自动运行中的上下文更改:
Template.content.onRendered(function() {
this.autorun(function() {
if (Template.currentData()) {
// the context just changed - insert code here
}
});
});
我不清楚这是否适用于您的特定情况,因为这种技术只会给您带来相当于onAfterChange
的效果。