将HTML标记传递到车把

Passing HTML markup into handlebars

本文关键字:HTML      更新时间:2023-09-26

我有一个不寻常的情况,客户端希望在从JSON对象传递给句柄的字符串中放置换行符。我试过转义字符,但它不是由DOM渲染的。有什么建议吗?


"company": "Lorem adscs ireland <br/> marketed as iuhmdsf in Europe"

var products = Data;
var theTemplateScript = $("#product-template").html();
var theTemplate = Handlebars.compile (theTemplateScript);
$("#marketed-products .products").append (theTemplate(products));

{{#items}}
<li><span class="company">{{company}}</li>
{{/items}}

上面代码的输出应该看起来像这样

Lorem adscs ireland
在欧洲以iuhmdsf销售

使用三括号,如{{{returnedHtml}}},在这种情况下,Handlebars不会转义值。

。E它将变成:

{{#items}}
<li><span class="company">{{{company}}}</li>
{{/items}}