简体   繁体   English

如何使用 BigCommerce 内置的车把助手按多个属性对对象数组进行排序?

[英]How do I sort an array of objects by multiple properties using BigCommerce built in handlebars helpers?

I have a requirement to sort an array of objects by multiple properties in a BigCommerce Stencil theme using their built in helpers before iterating over the properly sorted list.在迭代正确排序的列表之前,我需要使用 BigCommerce Stencil 主题中的多个属性对对象数组进行排序。
Can anyone please help me?谁能帮帮我吗?

My current code example:我当前的代码示例:

{{#each (sortBy (after customer.addresses 1) "last_name")}}
    <div class="panel panel--address">
        <div class="panel-body">
            <li>{{company}}</li>
            <li>{{address1}}</li>
            <li>{{address2}}</li>
            <li>{{city}}{{#if state}}, {{state}}{{/if}} {{zip}}</li>
            <li>{{country}}</li>
        </div>
    </div>
{{/each}}

Here I am iterating over a list of addresses in the customer's address book.在这里,我正在遍历客户通讯录中的地址列表。 I omit the first address, then sort the rest of the addresses by last name, then iterate over the sorted list to display some information about each address in a panel.我省略了第一个地址,然后按姓氏对地址的 rest 进行排序,然后遍历排序列表以在面板中显示有关每个地址的一些信息。

This all works great.这一切都很好。 What I now need to do is add first_name and address1 as the second and third properties.我现在需要做的是添加 first_name 和 address1 作为第二个和第三个属性。 This way if the user has multiple addresses with the same names the code should then sort the duplicates by address.这样,如果用户有多个具有相同名称的地址,则代码应按地址对重复项进行排序。

I was hoping for something as simple as我希望有一些简单的东西
{{#each (sortBy (after customer.addresses 1) "last_name, first_name, address1")}}
But separating the string with commas or spaces just returns the unsorted list.但是用逗号或空格分隔字符串只会返回未排序的列表。

Documentation for reference:参考文档:
https://developer.bigcommerce.com/stencil-docs/2a56bda466a81-handlebars-helpers-reference https://developer.bigcommerce.com/stencil-docs/2a56bda466a81-handlebars-helpers-reference

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM