繁体   English   中英

带有子文档的swig-template测试条件

[英]swig-template testing condition with subdocument

我有一个json:

var json = [{
        a: "asdf",
        b: "a",
        c: {1:{z:30,x:20,y:50},2:{z:30,x:50,y:30}}
    },
    {
        a: "fdsa",
        b: "o",
        c: {1:{z:10,x:20,y:50},2:{z:0,x:20,y:30}}
    }
]

我想有一个条件要检查:

  • 如果任何项目zx ,或yc目的是大于30 ,示出了用于值a

这可能吗? 我做了一些研究,但找不到任何答案。 请帮忙! 谢谢! 我试过了

{% for c,b in json.c %}

您的用例非常复杂,并且可能在服务器端做得更好,但是您可以用这种方法来...

{% for item in json %}
  {% set show = false %}
  {% for set in item.c %}
    {% for k in set %}
      {% if k > 30 %}
        {% set show = true %}
      {% endif %}
    {% endfor %}
  {% endfor %}
  {% if show %}
    {{ item.a }}
  {% endif %}
{% endfor %}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM