gpt4 book ai didi

javascript - 使用 mustache 模板渲染 "0"值

转载 作者:搜寻专家 更新时间:2023-11-01 04:32:59 26 4
gpt4 key购买 nike

我有一个模型,其属性值为“0”(零)。我的模板看起来像这样:

    {{#count}}{{{count}}} items{{/count}}
{{^count}}-{{/count}}

如果 myModel.count = 0,则呈现的 html 什么都没有。就像值“count”同时为 null 和 not null。

此案例的 Mustache 文档:https://github.com/janl/mustache.js#inverted-sections

最佳答案

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

It won't display a zero because zero is falsey. One option to get it to display is to set it to a non-falsey value (like the string '0')

关于javascript - 使用 mustache 模板渲染 "0"值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13402972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com