MemoJS在reactiveVar更改后运行脚本

时间:2015-05-24 19:57:34

标签: javascript meteor

我有一个帮助器,它从输入中评估代码并在div中显示它。现在,我希望在模板上呈现{{htmlMarkup}}后运行脚本。

Template.code.helpers({
    htmlMarkup:function(){
       $('#some-code').empty();
       return input.get();
    }
 });

问题是Template.code.onRendered仅在页面加载时调用一次。如何在呈现标记后运行代码?

1 个答案:

答案 0 :(得分:1)

您可以尝试在模板助手中使用Tracker.afterFlush

Template.code.helpers({
  htmlMarkup: function(){
    $('#some-code').empty();
    Tracker.afterFlush(function(){
      // your script goes here
    });
    return input.get();
  }
});