gpt4 book ai didi

google-closure-templates - 如何检查大 bean 模板中的空 map ?

转载 作者:行者123 更新时间:2023-12-05 00:01:45 24 4
gpt4 key购买 nike

我读过 docs对于 Google Soy/Closure 模板,但找不到任何方法来检查 Map 是否为空;我只能查找给定键的 map 值。有没有办法找出 map 的大小?

我目前的解决方法是用 null 替换任何空映射,然后检查模板中的 null,例如:

{if $myMap}
<!-- Do something that requires a non-empty map -->
{/if}

最佳答案

您可以使用 keys 函数获取 map 的键,然后对其使用 length,所以这应该可以工作:

{if length(keys($myMap)) == 0}
...
{/if}

关于google-closure-templates - 如何检查大 bean 模板中的空 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29359592/

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