我有一个JSON响应:
{"to_send":true,
"cart_items":[{"product_name":"Boys Waist Coat Shirt-Trouser and Cap- Grey",
"color":"Gray",
"size":"80 (6M-1 Years)",
"quantity":1,
"sub_total":1189.0},
{"product_name":"Boys Shirt, Pants And Coat - 3 Pcs Set With Bow - Dark Blue",
"color":"Navy",
"size":"2T (6M-1 Years)",
"quantity":2,
"sub_total":3418.0}]}
如何在液体语法中找到O / P以上的最高价格项目/产品?
答案 0 :(得分:1)
以下是液体语法的另一种方法,即创建自定义过滤器/标签
{% assign max_price = 0 %}
{% for item in obj.cart_items %}
{% if item.sub_total > max_price %}
{% assign max_price = item.sub_total %}
{% endif %}
{% endfor %}
<p>Max price: {{max_price}}</p>
答案 1 :(得分:0)
使用first
和last
过滤器也可以获取最小值或最大值。但是数组必须先排序:
{% assign max = obj.cart_items | sort: "sub_total" | last %}