问题
is there any way I can return innerHTML in helper? I mean something like this:
text: function(){
return "<p>It's working!</p>"
}
There would be more of those records since I loop them through {{#each}} loop and I tried to do it throught JQuery but had hard times naming classes/ID's so I would appreciate if someone could tell me how to do it with helper
回答1:
You can use Handlebars.SafeString:
text: function(){
return new Handlebars.SafeString("<p>It's working!</p>");
}
It will produce safe HTML string. Using not escaping with tripple brackets {{{...}}} is not secure if your helper returns something from user's input.
EDIT: in Meteor 1.* use Spacebars instead of Handlebars:
text: function(){
return new Spacebars.SafeString("<p>It's working!</p>");
}
回答2:
You can, just remember to call that helper with {{{...}}}
instead of {{...}}
so that it's not escaped:
{{#each paragraphs}}
{{{text}}}
{{/each}}
来源:https://stackoverflow.com/questions/26258324/meteor-js-return-innerhtml-in-helper