【发布时间】:2019-12-22 22:11:17
【问题描述】:
在“product.liquid”模板中,我想向我的 javascript 代码公开所有元字段。现在我有一个名为“mystuff”的命名空间,所以我这样做了......
// Copy all the METAFIELDS into the meta object
let meta = {
global: {{ product.metafields.global | json }},
mystuff: {{ product.metafields.mystuff | json }}
};
这行得通。但是,它需要我提前知道所有的命名空间并每行列出一个。我可以像这样以编程方式获取命名空间列表吗?
let meta = {
{% for ns in product.metafields.namespaces %}
{{ ns.name }} : {{ ns | json }},
{% endfor %}
};
我试过了,但这不起作用。有没有办法做到这一点?
【问题讨论】: