使用Emberjs将HTML插入视图 [英] Insert HTML into view using Emberjs
问题描述
刚刚开始学习emberjs,感谢您的帮助!
有一个类似的问题为angular.js提出并回答(AngularJS:将HTML插入视图),但是我找不到使用emberjs的答案。
说我在模板中有{{A}},在app.js中定义了A =html片段。
例如html片段如下:
< a href =www.google.com>去Google! < / A>
如果我在视图中呈现{{A}},我将获得完整的 html片段,但是我希望有一种方法可以告诉emberjs将{{A}}呈现为html。
Handlebars正在转义您的HTML片段,以保护您免受可能的恶意用户输入。您的问题的简短答案是使用Handlebars语法通过使用3个花括号在 raw
表单中呈现HTML: {{A}} }然而,我建议传递任何包含HTML的字符串,通过Handlebars
SafeString
保护自己的方法在文档中可以找到使用示例。
just start to learn emberjs, appreciate your help!
There is a similar question raised for angular.js and answered (AngularJS : Insert HTML into view), however I can not find an answer using emberjs.
say I have {{A}} in template, and A = "html fragment" , defined in app.js. for example a html fragment as below:
<a href="www.google.com"> Go to Google! </a>
if i render the {{A}} in the view I will get exactly the string of that "html fragment" , however I wish there is a way that i could tell emberjs to render {{A}} as html.
Handlebars is escaping your HTML fragment to protect you from possible malicious user input. The short answer to your question is to use Handlebars syntax to render the HTML in it's raw
form by using 3 curly braces: {{{A}}}
I would, however, recommend passing any string containing HTML trough Handlebars SafeString
method to protect yourself. An example of usage can be found in the docs.
这篇关于使用Emberjs将HTML插入视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!