使用小胡子模板渲染“ 0”值

JT7*_*703 5 javascript templates web-applications zero mustache

我有一个模型,其属性值为“ 0”(零)。我的模板如下所示:

    {{#count}}{{{count}}} items{{/count}}
    {{^count}}-{{/count}}
Run Code Online (Sandbox Code Playgroud)

如果为myModel.count = 0,则呈现的html为空。就像值“ count”为null,而不是同时为null。

这种情况下的小胡子文档:https : //github.com/janl/mustache.js#inverted-sections

JT7*_*703 2

@bobthecow 在他的评论中回答了这个问题:

它不会显示零,因为零是假的。让它显示的一种选择是将其设置为非错误值(如字符串“0”)