Shopify使用Liquid脚本对cart.items数组进行排序 [英] Shopify Sort cart.items array using Liquid script

查看:261
本文介绍了Shopify使用Liquid脚本对cart.items数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对cart.liquid文件中的cart.items数组进行排序.然后,我可以按期望的顺序在表中显示时间.

I want to sort the cart.items array in the cart.liquid file. And then I can display the times in the table in my expected order.

    {% for item in cart.items sort_by:item.line_price %}
    <div class="row">
      <div class="span12">
      <h1>Your cart</h1>
      <form action="/cart" method="post" id="cartform">
        <table>
        </table>
      </form>
      </div>
    </div>
    {% endfor %}

但是由于我不能在for语句中使用sort_by:item.line_price,所以代码无法正常工作.

But the code doesn't work since I can't use sort_by:item.line_price in for statement.

如何使用内置功能对数组进行排序?

How can I sort an array using built-in features?

另一个问题是Shopify Liquid不支持创建数组.如果我使用自己的算法对数组进行排序.但是如何将输出保存到新数组中?

The other problem is Shopify liquid doesn't support to create an array. if I use my own algorithm to sort the array. But how can I save the output to a new array?

非常感谢.

推荐答案

您可以将数据呈现为Javascript数据结构,然后对其进行排序.在Javascript中使用模板. Handlebars.js可以很好地实现这一目标.没有内置的排序.

You could just render your data to a Javascript data structure and then sort it. Use a template in Javascript. Handlebars.js works well for that. There is no built-in sort.

这篇关于Shopify使用Liquid脚本对cart.items数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆