Meteor.js在帮助程序中返回innerHTML [英] Meteor.js return innerHTML in helper

查看:114
本文介绍了Meteor.js在帮助程序中返回innerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在helper中返回innerHTML吗?
我的意思是这样的:

  text:function(){
return< p>它正在运作!< / p>
}

这些记录会有更多记录,因为我通过循环{{#each }}循环,我试图通过JQuery来做,但很难命名类/ ID,所以我会很感激,如果有人可以告诉我如何使用帮助器做到这一点

解决方案

您可以使用Handlebars.SafeString:

  text:function(){
返回新的Handlebars.SafeString(< p>它正在运作!< / p>);
}

它会产生安全的HTML字符串。如果您的助手从用户输入中返回某些内容,{{{...}}}不是安全的。{b} {b} {b} > in Meteor 1. *使用SpaceBars而不是Handlebars:

  text:function(){
返回新的Spacebars。 SafeString(< p>正在运作!< / p>);
}


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

解决方案

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>");
}

这篇关于Meteor.js在帮助程序中返回innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆