[英]Escaping curly braces in a label in handlebars
I have handlebar code that prints out a list of labels. 我有打印出标签列表的车把代码。
This values are:
{{#each theObj.Options}}
{{#if @last}}
{{this.valueLabel}}
{/if}}
{{#unless @last}}
{{this.valueLabel},
{{/unless}}
{{/each}}.
</p>{{/compare}}
The valueLabels are: valueLabel是:
Value A
Value B
{Test}
The handlebar code prints out: 车把代码打印出来:
The values are: Value A, Value B, .
I need to get the last {Test} to print out. 我需要获取最后的{Test}才能打印出来。 How do I do that?
我怎么做? The printout should be:
打印输出应为:
The values are: Value A, Value B, {Test}.
Thanks. 谢谢。
Setting this up in a quick Code Pen seemed to yield the desired result. 用快速的代码笔进行设置似乎可以达到预期的效果。 This is with three caveats:
这有三个警告:
Could you clarify what is in the 'theObj' object so we can troubleshoot that? 您能否弄清楚“ theObj”对象中的内容是什么,以便我们进行故障排除?
HTML 的HTML
<div id="app"></div>
<script id="entry-template" type="text/x-handlebars-template">
This values are:
{{#each theObj.Options}}
{{#if @last}}
{{this.valueLabel}}
{{/if}}
{{#unless @last}}
{{this.valueLabel}},
{{/unless}}
{{/each}}.
</script>
JavaScript 的JavaScript
var theObj = {
Options: [{valueLabel: 'Value A'}, {valueLabel: 'Value B'}, {valueLabel: '{Test}'}]
};
var source = document.getElementById('entry-template').innerHTML;
var template = Handlebars.compile(source);
var context = {theObj: theObj};
var html = template(context);
document.getElementById('app').innerHTML = html;
console.log(html);
You can check out the Code Pen example here: 您可以在此处查看代码笔示例:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.