Is there any way to insert a callback before/after

2019-09-19 01:36发布

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();
});

Is there any current way I can achieve this with the existing Template api?

1条回答
Summer. ? 凉城
2楼-- · 2019-09-19 02:01

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
    }
  });
});

I'm unclear if that works for your particular case because this technique only gets you the equivalent of onAfterChange.

查看更多
登录 后发表回答