Meteor.js return innerHTML in helper

六眼飞鱼酱① 提交于 2019-12-24 00:47:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!