Mustache.js 有条件的 Header
Mustache.js Conditional Header
使用 mustache.js,我只想显示 header(颜色),前提是颜色数组中确实有值。一种似乎有效的方法是:
{colors: [] }
{{#colors.0}}<h1>Colors</h1>{{/colors.0}}
{{#colors}}
* {{.}}
{{/colors}}
但感觉还有更好的方法。我在这里遗漏了什么吗?
因为它是 JavaScript,所以您可以使用 {{# colors.length }}
,因为只要数组非空,这就是真实的。
使用 mustache.js,我只想显示 header(颜色),前提是颜色数组中确实有值。一种似乎有效的方法是:
{colors: [] }
{{#colors.0}}<h1>Colors</h1>{{/colors.0}}
{{#colors}}
* {{.}}
{{/colors}}
但感觉还有更好的方法。我在这里遗漏了什么吗?
因为它是 JavaScript,所以您可以使用 {{# colors.length }}
,因为只要数组非空,这就是真实的。