Mustache.js: 如何在 mustache 变量前打印文字 {?

创建于 2014-02-16  ·  3评论  ·  资料来源: janl/mustache.js

我有一个胡子模板,我想用 {} 包围变量

var output = Mustache.render('<td>{{{start.lat}}, {{start.lon}}}</td>', routeObj);

我想输出一个带有字符串的<td>{1.8978, 30.4545}

{{{ 在 mustache 中具有特殊含义,因此它不起作用。 有没有办法摆脱小胡子中的第一个 {?

最有用的评论

我能想到的两种方法:

  1. 暂时将定界符设置为大括号之外的其他内容,然后在打印大括号后将其切换回来

var output = Mustache.render('<td>{{=<% %>=}}{<% start.lat %>, <% start.lon %>}<%={{ }}=%></td>', routeObj);

  1. 使用变量打印 { 和 }

routeObj.openbrace = '{'; routeObj.closebrace = '}'; var output = Mustache.render('<td>{{openbrace}}{{start.lat}}, {{start.lon}}{{closebrace}}</td>', routeObj);

所有3条评论

我能想到的两种方法:

  1. 暂时将定界符设置为大括号之外的其他内容,然后在打印大括号后将其切换回来

var output = Mustache.render('<td>{{=<% %>=}}{<% start.lat %>, <% start.lon %>}<%={{ }}=%></td>', routeObj);

  1. 使用变量打印 { 和 }

routeObj.openbrace = '{'; routeObj.closebrace = '}'; var output = Mustache.render('<td>{{openbrace}}{{start.lat}}, {{start.lon}}{{closebrace}}</td>', routeObj);

@alanhamlett所说的,还有 html 实体: &#123;{

这一切都有效。 谢谢!

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

zekth picture zekth  ·  18评论

MatthijsZw picture MatthijsZw  ·  18评论

ForbesLindesay picture ForbesLindesay  ·  14评论

barbalex picture barbalex  ·  5评论

kuldeepdhaka picture kuldeepdhaka  ·  9评论