2016-09-07 5 views
1

を使用して、オブジェクトのリストで最大値を見つける:は、私は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のmax価格アイテム/製品を見つけることができますか?

答えて

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> 
カスタムフィルタ/タグを作成することです方法です
関連する問題