有什么方法可以插入回调 before/after 模板上下文已更新?

Is there any way to insert a callback before/after a templates context is updated?

我知道 Template.onRendered,但是我需要销毁和设置一些在实际上下文更新时作用于 dom 的插件。

也就是说我有内容模板,我需要类似于以下内容的内容:

Template.content.onBeforeChange(function () {
  $(".editor").editable("destroy");
});

Template.content.onAfterChange(function () {
  $(".editor").editable();
});

目前有什么方法可以使用现有模板实现此目的吗api?

您应该能够像这样检测 template autorun by looking at currentData 中的上下文更改:

Template.content.onRendered(function() {
  this.autorun(function() {
    if (Template.currentData()) {
      // the context just changed - insert code here
    }
  });
});

我不清楚这是否适用于您的特定情况,因为这种技术只能让您相当于 onAfterChange