帮助器应该查找主题标签并使它们成为路由/链接。相反,它使文本不显示。我该如何解决。提前致谢。这是代码。
handlebar.js
Handlebars.registerHelper('hashtag', function(posttext) {
posttext.html();
posttext = posttext.replace(/#(\w+)/g, "<a href='https://www.google.com/?q=$1' target='_blank'>$&</a>");
posttext.html(posttext);
});
postidem.js
<h3 class="text">{{hashtag title}}</h3>
<p class="text">{{hashtag posttext}}</p>
答案 0 :(得分:0)
试试这个:
Handlebars.registerHelper('hashtag', function(posttext) {
// DEBUG START : just to know that `posttext` is really what you want; remove later;
console.log("hashtag",posttext);
// DEBUG END
return posttext.replace(/#(\w+)/g, "<a href='https://www.google.com/?q=$1' target='_blank'>$&</a>");
});
注意:
Template.registerHelper
适用于Meteor 0.9.1及更新版Handlebars.registerHelper
适用于每个版本。请记住在三角形花括号中放置帮助器,因为它返回html;
Meteor.startup
<强> Proof 强>