【发布时间】:2015-08-07 04:33:40
【问题描述】:
我正在尝试对辅助函数{{htmlMarkup}} 的每次求值进行一些 DOM 操作。问题是当页面加载时,在模板有 DOM 之前触发了帮助器。
Template.myTemplate.helpers({
htmlMarkup:function(){
var tmpl = Template.instance();
tmpl.$('.code-container').empty();
Tracker.afterFlush(function(){
Prism.highlightElement(tmpl.$('.code-container')[0]);
});
return input.get();
}
});
我将收到错误消息Exception in template helper: Error: Can't use $ on template instance with no DOM。我试图检查tmpl.firstNode 是否未定义,但它不起作用。解决这个问题的最佳方法是什么?
【问题讨论】:
标签: javascript jquery dom meteor