我有一个可以打印标签列表的手柄条形码。
This values are:
{{#each theObj.Options}}
{{#if @last}}
{{this.valueLabel}}
{/if}}
{{#unless @last}}
{{this.valueLabel},
{{/unless}}
{{/each}}.
</p>{{/compare}}这些valueLabels是:
Value A
Value B
{Test}手柄条码打印出来:
The values are: Value A, Value B, .我需要将最后的{Test}打印出来。我该怎么做?打印输出应为:
The values are: Value A, Value B, {Test}.谢谢。
发布于 2018-04-24 06:55:17
在一个快速的Code Pen中设置它似乎可以产生想要的结果。这有三点需要注意:
您能澄清一下'theObj‘对象中有什么吗?这样我们就可以解决这个问题了。
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
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);您可以在此处查看Code Pen示例:
请参阅CodePen上尼古拉斯·劳伦斯(@nicholaslawrencestudio)的the Pen Escaping curly braces in a label in handlebars。
https://stackoverflow.com/questions/49990341
复制相似问题