我正在使用 JS 和液体执行以下操作:
const variantsWithInventoryData = {};
// Loop through each variant and assign to the object
{% for variant in product.variants %}
variantsWithInventoryData["{{ variant.id }}"] = {
inventory_quantity: {{ variant.inventory_quantity }},
inventory_policy: "{{ variant.inventory_policy }}",
inventory_management: "{{ variant.inventory_management }}",
inventory_item_id: 0
};
{% endfor %}
如何完全使用液体来实现上述目标?
谢谢!
{% for variant in variants %}
{% assign id = variant.id %}
{% assign size = variant. quantity %} // remove space after "."
{% assign color = variant. color %} // remove space after "."
{% assign res = res | append: id %}
{% assign res = res | append: " (" %}
{% assign res = res | append: size %}
{% assign res = res | append: ", " %}
{% assign res = res | append: color %}
{% assign res = res | append: "); " %}
{% endfor %}
{{ res }}