【问题标题】:Sorting by second element of split array in liquid按液体中拆分数组的第二个元素排序
【发布时间】:2017-04-05 09:59:16
【问题描述】:

我是 Liquid 新手,如果这很明显,请见谅。

我有一些数据,其标题在我要排序的实际文本之前以 A1、B10、C64 等为前缀,例如,“A1 东西”“B10 无”“A23 另一个”。

如果我使用

{% assign itemssorted = product.ds_related_products | sort: 'title' %}
{% for item in itemssorted %}

然后我得到根据前缀排序的项目,而我 想要 是在前缀 之后按文本排序的项目。

有没有类似的

{% assign itemssorted = product.ds_related_products | sort: 'title' | split: ' ' .... %}

我可以用它来实现吗?

【问题讨论】:

    标签: sorting liquid


    【解决方案1】:

    尝试更改要排序的变量的排序:价格:

    {% assign products = collection.products | sort: 'price' %}
    {% for product in products %}
        <h4>{{ product.title }}</h4>
    {% endfor %}
    
    <!-- products = "a", "b", "A", "B" -->
    {% assign products = collection.products | sort: 'title' %}
    {% for product in products %}
        {{ product.title }}
    {% endfor %}
    

    【讨论】:

    • 感谢您的回复,但我不确定我是否理解您的方法 - 价格与我的排序要求无关,我只是想在排序之前从 title 属性中删除一些前缀文本通过剩余的标题文本,想知道我是否可以在液体中的一个语句中做到这一点?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2021-12-08
    • 1970-01-01
    相关资源
    最近更新 更多