使用 Mustache 循环 json
Loop json using Mustache
我知道了:
field: [
{ text: 'text 1' },
{ price1: '10' },
{ price2: '16' },
{ text: 'text2' },
{ price1: '20' },
{ price2: '23' }
];
我想用小胡子重复数据,我试过:
{{#field}}
<span>{{text}}</span>
{{/field}}
但是它不起作用,有人可以帮忙吗?
在 mustache 中遍历 JSON 时,您可以执行以下操作
{{#each field}}
<span> {{ text }} </span>
{{/each}}
顺便说一下,您的 JSON 没有正确呈现,我认为每个 JSON 对象都必须看起来像这样
field: [
{
text: 'text 1,
price1: '10',
price2: '16'
},
{
text: 'text2',
price1: '20',
price2: '23'
},
];
这样你就可以访问对象中的所有元素
我知道了:
field: [
{ text: 'text 1' },
{ price1: '10' },
{ price2: '16' },
{ text: 'text2' },
{ price1: '20' },
{ price2: '23' }
];
我想用小胡子重复数据,我试过:
{{#field}}
<span>{{text}}</span>
{{/field}}
但是它不起作用,有人可以帮忙吗?
在 mustache 中遍历 JSON 时,您可以执行以下操作
{{#each field}}
<span> {{ text }} </span>
{{/each}}
顺便说一下,您的 JSON 没有正确呈现,我认为每个 JSON 对象都必须看起来像这样
field: [
{
text: 'text 1,
price1: '10',
price2: '16'
},
{
text: 'text2',
price1: '20',
price2: '23'
},
];
这样你就可以访问对象中的所有元素