我正在构建一个FAQ页面,我想将包含问题和答案的数组返回到我的空格键帮助器中。
faq.js
var faqContents = [
{
number: "One",
question: "Who needs acupuncture?",
answer: "<p>If you are suffering from pain or have a health problem that has not responded satisfactorily to Western medicine, you may benefit tremendously from acupuncture and herbs. In many cases, acupuncture has been more effective than conventional Western treatments. <br/>Your most valuable asset is good health. Invest in it wisely. Consider acupuncture.</p>")
}, {
number: "Two",
question: "What can I expect if treated?",
answer: "<p>Many conditions may be alleviated very rapidly by acupuncture; however, some conditions which have risen over a course of years will only be relieved with slow, steady progress. As in any form of healing, the patient’s attitude, diet, determination, and lifestyle will affect the outcome of a course of treatment.</p><p>Although there are techniques in Traditional Oriental Medicine for healing most conditions, there are medical circumstances that can be dealt with more effectively by Western Medicine. In such cases, your acupuncturist will recommend that you contact a physician. As in the case in China, acupuncture should be seen as complementary with Western Medicine.</p>"
}
];
Template.faq.helpers({
faqContents: function(){
return faqContents;
}
});
但是下面的代码在浏览器视图中呈现文本中的实际html标记。
{{#each faqContents}}
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse{{number}}">{{question}}</a>
</h4>
</div>
<div id="collapse{{number}}" class="panel-collapse collapse">
<div class="panel-body">
{{answer}}
</div>
</div>
</div>
{{/each }}
不确定如何继续。
答案 0 :(得分:1)
而不是{{answer}}
使用{{{ answer }}}
。这告诉Meteor不要转义HTML标记,只输出原始HTML。查看Github Repo上的空格键文档。
但不建议仅仅因为安全性。什么阻止你这样使用它:
<p>{{ answer }}</p>