有没有办法在模板上下文更新之前/之后插入回调? [英] Is there any way to insert a callback before/after a templates context is updated?
问题描述
我知道Template.onRendered,但是我需要销毁并设置一些在实际上下文更新时对dom起作用的插件.
I'm aware of Template.onRendered, however I have the need to destroy and setup some plugins that act on the dom when the actual context is updated.
所以说我有内容模板,我需要类似以下内容的东西:
So saying I have content template, I'd need something similar to the following:
Template.content.onBeforeChange(function () {
$(".editor").editable("destroy");
});
Template.content.onAfterChange(function () {
$(".editor").editable();
});
使用现有的模板API,有什么当前的方法可以实现这一目标?
Is there any current way I can achieve this with the existing Template api?
推荐答案
您应该能够在 currentData ="=" nofollow>模板自动运行:
You should be able to detect a context change within a template autorun by looking at currentData like this:
Template.content.onRendered(function() {
this.autorun(function() {
if (Template.currentData()) {
// the context just changed - insert code here
}
});
});
我不清楚这是否适用于您的特定情况,因为此技术只能使您获得与onAfterChange
相同的效果.
I'm unclear if that works for your particular case because this technique only gets you the equivalent of onAfterChange
.
这篇关于有没有办法在模板上下文更新之前/之后插入回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!