在液体中循环
Looping in liquid
我有一个简单的应用程序,修改产品并给编辑select“其他人也购买了这个产品”。
一切正常,我可以在编辑器保存时保存我需要的值,但我可以用液体循环渲染它们。无论我尝试什么,无论我 select 有多少产品,我都会得到一个迭代。我保存在我的元字段中的数据看起来像这样(抱歉臃肿 json 我会把它煮下来,只使用我需要的道具,当我可以让循环工作时:)
如您所见,它是一个包含 2 个对象的数组,我不明白为什么我不能在液体中像这样循环它们:
{% assign options = product.metafields.custom.option_items %}
{%- for value in options -%}
<div>
{{ value }}
</div><br>
{%- endfor -%}
[
{
"availablePublicationCount": 2,
"createdAt": "2021-09-22T18:09:48Z",
"descriptionHtml": "Den norske klippeø Borgan har lagt navn til denne elegante bluse! Borgan Blusen strikkes i vores 100% Cashmere garn, som er utroligt blødt og let. Blusen er perfekt til efterårets og vinterens vindblæste dage, da den altid holder dig varm. Den lune cashmere smyger sig mod huden, og er et fantastisk garn at strikke med.",
"handle": "blue-jeans",
"hasOnlyDefaultVariant": false,
"id": "gid://shopify/Product/7361861910702",
"images": [ { "id": "gid://shopify/ProductImage/30202448838830",
"originalSrc": "https://cdn.shopify.com/s/files/1/0600/4614/7758/products/kit_couture_borgan_pullover_image.jpg?v=1632740318"}],
"options":[{"id":"gid://shopify/ProductOption/9282040234158","name":"Size","position":1,"values":["S","M","L","XL"]},{"id":"gid://shopify/ProductOption/9293785039022","name":"Color","position":2,"values":["Grå","Lysegrå","Camel","Navy"]}],"productType":"","publishedAt":"2021-09-22T18:10:00Z","tags":[],"templateSuffix":"","title":"Borgan Bluse","totalInventory":0,"tracksInventory":false,"updatedAt":"2021-10-18T08:15:00Z","variants":[{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - S / Grå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213267118","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864820398","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":1,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"S","__typename":"SelectedOption"},{"value":"Grå","__typename":"SelectedOption"}],"sku":"sku-de-123","taxable":true,"title":"S / Grå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - S / Lysegrå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213299886","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864853166","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":2,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"S","__typename":"SelectedOption"},{"value":"Lysegrå","__typename":"SelectedOption"}],"sku":"sku-de-124","taxable":true,"title":"S / Lysegrå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - S / Camel","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213332654","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864885934","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":3,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"S","__typename":"SelectedOption"},{"value":"Camel","__typename":"SelectedOption"}],"sku":"sku-de-125","taxable":true,"title":"S / Camel","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - S / Navy","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213365422","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864918702","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":4,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"S","__typename":"SelectedOption"},{"value":"Navy","__typename":"SelectedOption"}],"sku":"sku-de-126","taxable":true,"title":"S / Navy","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - M / Grå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213398190","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864951470","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":5,"price":"1275.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"M","__typename":"SelectedOption"},{"value":"Grå","__typename":"SelectedOption"}],"sku":"sku-de-127","taxable":true,"title":"M / Grå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - M / Lysegrå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213430958","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864984238","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":6,"price":"1275.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"M","__typename":"SelectedOption"},{"value":"Lysegrå","__typename":"SelectedOption"}],"sku":"sku-de-128","taxable":true,"title":"M / Lysegrå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - M / Camel","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213463726","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865017006","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":7,"price":"1275.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"M","__typename":"SelectedOption"},{"value":"Camel","__typename":"SelectedOption"}],"sku":"sku-de-129","taxable":true,"title":"M / Camel","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - M / Navy","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213496494","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865049774","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":8,"price":"1275.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"M","__typename":"SelectedOption"},{"value":"Navy","__typename":"SelectedOption"}],"sku":"sku-de-130","taxable":true,"title":"M / Navy","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - L / Grå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213529262","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865082542","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":9,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"L","__typename":"SelectedOption"},{"value":"Grå","__typename":"SelectedOption"}],"sku":"sku-de-131","taxable":true,"title":"L / Grå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - L / Lysegrå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213562030","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865115310","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":10,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"L","__typename":"SelectedOption"},{"value":"Lysegrå","__typename":"SelectedOption"}],"sku":"sku-de-132","taxable":true,"title":"L / Lysegrå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - L / Camel","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213594798","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865148078","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":11,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"L","__typename":"SelectedOption"},{"value":"Camel","__typename":"SelectedOption"}],"sku":"sku-de-133","taxable":true,"title":"L / Camel","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - L / Navy","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213627566","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865180846","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":12,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"L","__typename":"SelectedOption"},{"value":"Navy","__typename":"SelectedOption"}],"sku":"sku-de-134","taxable":true,"title":"L / Navy","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - XL / Grå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213660334","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865213614","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":13,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"XL","__typename":"SelectedOption"},{"value":"Grå","__typename":"SelectedOption"}],"sku":"sku-de-135","taxable":true,"title":"XL / Grå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - XL / Lysegrå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213693102","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865246382","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":14,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"XL","__typename":"SelectedOption"},{"value":"Lysegrå","__typename":"SelectedOption"}],"sku":"sku-de-136","taxable":true,"title":"XL / Lysegrå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - XL / Camel","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213725870","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865279150","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":15,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"XL","__typename":"SelectedOption"},{"value":"Camel","__typename":"SelectedOption"}],"sku":"sku-de-137","taxable":true,"title":"XL / Camel","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - XL / Navy","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213758638","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865311918","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":16,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"XL","__typename":"SelectedOption"},{"value":"Navy","__typename":"SelectedOption"}],"sku":"sku-de-138","taxable":true,"title":"XL / Navy","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"}],"vendor":"kit-draft","status":"ACTIVE"},{"availablePublicationCount":2,"createdAt":"2021-10-08T10:47:28Z","descriptionHtml":"sad sad asd sa dsad sadasd asd sa d","handle":"test-test","hasOnlyDefaultVariant":true,"id":"gid://shopify/Product/7394530623662","images":[{"id":"gid://shopify/ProductImage/30318977319086","originalSrc":"https://cdn.shopify.com/s/files/1/0600/4614/7758/products/kit-couture-advendt-2021-bred.jpg?v=1633690050"},{"id":"gid://shopify/ProductImage/30318977155246","originalSrc":"https://cdn.shopify.com/s/files/1/0600/4614/7758/products/a3ae948d554f0af0567db4da524f40fa4c5709d3.png?v=1633690050"}],"options":[{"id":"gid://shopify/ProductOption/9322976772270","name":"Title","position":1,"values":["Default Title"]}],"productType":"","publishedAt":"2021-10-08T10:47:30Z","tags":[],"templateSuffix":"","title":"TEST TEST","totalInventory":12,"tracksInventory":true,"updatedAt":"2021-10-08T11:04:11Z","variants":[{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-10-08T10:47:28Z","displayName":"TEST TEST - Default Title","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41460212957358","inventoryItem":{"id":"gid://shopify/InventoryItem/43557095145646","__typename":"InventoryItem"},"inventoryManagement":"SHOPIFY","inventoryPolicy":"CONTINUE","inventoryQuantity":12,"position":1,"price":"345.00","product":{"id":"gid://shopify/Product/7394530623662","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"Default Title","__typename":"SelectedOption"}],"sku":"1234","taxable":true,"title":"Default Title","updatedAt":"2021-10-08T10:47:28Z","weight":0,"weightUnit":"KILOGRAMS"}],"vendor":"nike","status":"ACTIVE"}]
假设您正在使用新的 Metafield type json 即 returns json_string。要遍历元字段值,您必须使用 value 属性.
访问该值
{% assign options = product.metafields.custom.option_items.value %}
{%- for option in options -%}
<div>
{{ option.availablePublicationCount }}
</div>
<br>
{%- endfor -%}
我有一个简单的应用程序,修改产品并给编辑select“其他人也购买了这个产品”。
一切正常,我可以在编辑器保存时保存我需要的值,但我可以用液体循环渲染它们。无论我尝试什么,无论我 select 有多少产品,我都会得到一个迭代。我保存在我的元字段中的数据看起来像这样(抱歉臃肿 json 我会把它煮下来,只使用我需要的道具,当我可以让循环工作时:)
如您所见,它是一个包含 2 个对象的数组,我不明白为什么我不能在液体中像这样循环它们:
{% assign options = product.metafields.custom.option_items %}
{%- for value in options -%}
<div>
{{ value }}
</div><br>
{%- endfor -%}
[
{
"availablePublicationCount": 2,
"createdAt": "2021-09-22T18:09:48Z",
"descriptionHtml": "Den norske klippeø Borgan har lagt navn til denne elegante bluse! Borgan Blusen strikkes i vores 100% Cashmere garn, som er utroligt blødt og let. Blusen er perfekt til efterårets og vinterens vindblæste dage, da den altid holder dig varm. Den lune cashmere smyger sig mod huden, og er et fantastisk garn at strikke med.",
"handle": "blue-jeans",
"hasOnlyDefaultVariant": false,
"id": "gid://shopify/Product/7361861910702",
"images": [ { "id": "gid://shopify/ProductImage/30202448838830",
"originalSrc": "https://cdn.shopify.com/s/files/1/0600/4614/7758/products/kit_couture_borgan_pullover_image.jpg?v=1632740318"}],
"options":[{"id":"gid://shopify/ProductOption/9282040234158","name":"Size","position":1,"values":["S","M","L","XL"]},{"id":"gid://shopify/ProductOption/9293785039022","name":"Color","position":2,"values":["Grå","Lysegrå","Camel","Navy"]}],"productType":"","publishedAt":"2021-09-22T18:10:00Z","tags":[],"templateSuffix":"","title":"Borgan Bluse","totalInventory":0,"tracksInventory":false,"updatedAt":"2021-10-18T08:15:00Z","variants":[{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - S / Grå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213267118","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864820398","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":1,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"S","__typename":"SelectedOption"},{"value":"Grå","__typename":"SelectedOption"}],"sku":"sku-de-123","taxable":true,"title":"S / Grå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - S / Lysegrå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213299886","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864853166","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":2,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"S","__typename":"SelectedOption"},{"value":"Lysegrå","__typename":"SelectedOption"}],"sku":"sku-de-124","taxable":true,"title":"S / Lysegrå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - S / Camel","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213332654","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864885934","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":3,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"S","__typename":"SelectedOption"},{"value":"Camel","__typename":"SelectedOption"}],"sku":"sku-de-125","taxable":true,"title":"S / Camel","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - S / Navy","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213365422","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864918702","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":4,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"S","__typename":"SelectedOption"},{"value":"Navy","__typename":"SelectedOption"}],"sku":"sku-de-126","taxable":true,"title":"S / Navy","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - M / Grå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213398190","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864951470","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":5,"price":"1275.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"M","__typename":"SelectedOption"},{"value":"Grå","__typename":"SelectedOption"}],"sku":"sku-de-127","taxable":true,"title":"M / Grå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - M / Lysegrå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213430958","inventoryItem":{"id":"gid://shopify/InventoryItem/43466864984238","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":6,"price":"1275.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"M","__typename":"SelectedOption"},{"value":"Lysegrå","__typename":"SelectedOption"}],"sku":"sku-de-128","taxable":true,"title":"M / Lysegrå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - M / Camel","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213463726","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865017006","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":7,"price":"1275.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"M","__typename":"SelectedOption"},{"value":"Camel","__typename":"SelectedOption"}],"sku":"sku-de-129","taxable":true,"title":"M / Camel","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - M / Navy","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213496494","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865049774","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":8,"price":"1275.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"M","__typename":"SelectedOption"},{"value":"Navy","__typename":"SelectedOption"}],"sku":"sku-de-130","taxable":true,"title":"M / Navy","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - L / Grå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213529262","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865082542","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":9,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"L","__typename":"SelectedOption"},{"value":"Grå","__typename":"SelectedOption"}],"sku":"sku-de-131","taxable":true,"title":"L / Grå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - L / Lysegrå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213562030","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865115310","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":10,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"L","__typename":"SelectedOption"},{"value":"Lysegrå","__typename":"SelectedOption"}],"sku":"sku-de-132","taxable":true,"title":"L / Lysegrå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - L / Camel","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213594798","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865148078","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":11,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"L","__typename":"SelectedOption"},{"value":"Camel","__typename":"SelectedOption"}],"sku":"sku-de-133","taxable":true,"title":"L / Camel","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - L / Navy","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213627566","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865180846","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":12,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"L","__typename":"SelectedOption"},{"value":"Navy","__typename":"SelectedOption"}],"sku":"sku-de-134","taxable":true,"title":"L / Navy","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - XL / Grå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213660334","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865213614","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":13,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"XL","__typename":"SelectedOption"},{"value":"Grå","__typename":"SelectedOption"}],"sku":"sku-de-135","taxable":true,"title":"XL / Grå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - XL / Lysegrå","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213693102","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865246382","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":14,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"XL","__typename":"SelectedOption"},{"value":"Lysegrå","__typename":"SelectedOption"}],"sku":"sku-de-136","taxable":true,"title":"XL / Lysegrå","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - XL / Camel","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213725870","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865279150","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":15,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"XL","__typename":"SelectedOption"},{"value":"Camel","__typename":"SelectedOption"}],"sku":"sku-de-137","taxable":true,"title":"XL / Camel","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"},{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-09-27T14:44:31Z","displayName":"Borgan Bluse - XL / Navy","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41371213758638","inventoryItem":{"id":"gid://shopify/InventoryItem/43466865311918","__typename":"InventoryItem"},"inventoryManagement":"NOT_MANAGED","inventoryPolicy":"DENY","inventoryQuantity":0,"position":16,"price":"1130.00","product":{"id":"gid://shopify/Product/7361861910702","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"XL","__typename":"SelectedOption"},{"value":"Navy","__typename":"SelectedOption"}],"sku":"sku-de-138","taxable":true,"title":"XL / Navy","updatedAt":"2021-09-27T14:44:31Z","weight":0,"weightUnit":"KILOGRAMS"}],"vendor":"kit-draft","status":"ACTIVE"},{"availablePublicationCount":2,"createdAt":"2021-10-08T10:47:28Z","descriptionHtml":"sad sad asd sa dsad sadasd asd sa d","handle":"test-test","hasOnlyDefaultVariant":true,"id":"gid://shopify/Product/7394530623662","images":[{"id":"gid://shopify/ProductImage/30318977319086","originalSrc":"https://cdn.shopify.com/s/files/1/0600/4614/7758/products/kit-couture-advendt-2021-bred.jpg?v=1633690050"},{"id":"gid://shopify/ProductImage/30318977155246","originalSrc":"https://cdn.shopify.com/s/files/1/0600/4614/7758/products/a3ae948d554f0af0567db4da524f40fa4c5709d3.png?v=1633690050"}],"options":[{"id":"gid://shopify/ProductOption/9322976772270","name":"Title","position":1,"values":["Default Title"]}],"productType":"","publishedAt":"2021-10-08T10:47:30Z","tags":[],"templateSuffix":"","title":"TEST TEST","totalInventory":12,"tracksInventory":true,"updatedAt":"2021-10-08T11:04:11Z","variants":[{"availableForSale":true,"barcode":"","compareAtPrice":null,"createdAt":"2021-10-08T10:47:28Z","displayName":"TEST TEST - Default Title","fulfillmentService":{"id":"gid://shopify/FulfillmentService/manual","inventoryManagement":false,"productBased":true,"serviceName":"Manual","type":"MANUAL"},"id":"gid://shopify/ProductVariant/41460212957358","inventoryItem":{"id":"gid://shopify/InventoryItem/43557095145646","__typename":"InventoryItem"},"inventoryManagement":"SHOPIFY","inventoryPolicy":"CONTINUE","inventoryQuantity":12,"position":1,"price":"345.00","product":{"id":"gid://shopify/Product/7394530623662","__typename":"Product"},"requiresShipping":true,"selectedOptions":[{"value":"Default Title","__typename":"SelectedOption"}],"sku":"1234","taxable":true,"title":"Default Title","updatedAt":"2021-10-08T10:47:28Z","weight":0,"weightUnit":"KILOGRAMS"}],"vendor":"nike","status":"ACTIVE"}]
假设您正在使用新的 Metafield type json 即 returns json_string。要遍历元字段值,您必须使用 value 属性.
访问该值{% assign options = product.metafields.custom.option_items.value %}
{%- for option in options -%}
<div>
{{ option.availablePublicationCount }}
</div>
<br>
{%- endfor -%}