Ember handlebars 连接字符串和变量总是附加白色 space

Ember handlebars concat string and variable always appends white space

var categories = ['item1', 'item2', 'item3']

{{#each categories as |item|}}
  {{concat ',' item}}
{{/each}}

将产生: ,项目 1 ,项目 2 ,项目 3

如何删除每个字符串前的空格?

您可以使用 ~ 修饰符删除空格:

var categories = ['item1', 'item2', 'item3']

{{#each categories as |item|}}
  {{~ concat ',' item ~}}
{{/each}}

这将删除前后的空格。有关详细信息,请参阅 "Whitespace Control" 下的 Twiddle for a working reproduction, and Handlebar.js' documentation