【问题标题】:Break out of two loops in Shopify Liquid在 Shopify Liquid 中打破两个循环
【发布时间】:2017-05-28 13:21:44
【问题描述】:

如何打破液体中的两个循环。到目前为止我有,这似乎对我不起作用。

{% for x in a %}

  {% for y in b %}

    {% if y = 2 %}      
    {% break %}
    // When this loop breaks, the parent for loop should also break
    {% endif %}

  {% endfor %}

{% endfor %}

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    您可以添加一个标志并在更改后检查。

    {% assign break_loop = false %}
    {% for x in a %}
    
      {% for y in b %}
    
        {% if y = 2 %}      
        {% break %}
        {% assign break_loop = true %}
        // When this loop breaks, the parent for loop should also break
        {% endif %}
    
      {% endfor %}
    
      {% if break_loop %}
        {% break %}
      {% endif %}
    
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-28
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      相关资源
      最近更新 更多