如何在小胡子循环中的每两个项目上添加一个包装器?
How can I add a wrapper on every two items in mustache loop?
我在 mustache
中循环遍历 json 时试图得到这个结果
<div class="group">
<article></article>
<article></article>
</div>
<div class="group">
<article></article>
<article></article>
</div>
这是我唯一会做的事情
{{# books }}
<article> ... </article>
{{/ books }}
ps - 我正在使用模式实验室
这里是模式实验室节点的维护者。
我的建议与 O_Z 的评论相似,即更改数据以利用 listitems.json 可能是更好的选择。
您可以在这里阅读全部内容:http://patternlab.io/docs/data-listitems.html
如果你真的想要这样的配对项目,要点就是有一个模板,然后像这样:
{{# listItems.three}}
<div class="group">
<article>...</article>
<article>...</article>
</div>
{{/ listItems.three}}
您的 listitems.json
将对应为:
{
"1": {
"articles" : [
{...},
{...}
]
},
"2": {
"articles" : [
{...},
{...}
]
},
"3": {
"articles" : [
{...},
{...}
]
}
}
listitems.three
没有 link 输出文章的数量,只是潜在的数据量。使用这种方法,物品的顺序实际上也是随机的。
我在 mustache
中循环遍历 json 时试图得到这个结果<div class="group">
<article></article>
<article></article>
</div>
<div class="group">
<article></article>
<article></article>
</div>
这是我唯一会做的事情
{{# books }}
<article> ... </article>
{{/ books }}
ps - 我正在使用模式实验室
这里是模式实验室节点的维护者。
我的建议与 O_Z 的评论相似,即更改数据以利用 listitems.json 可能是更好的选择。
您可以在这里阅读全部内容:http://patternlab.io/docs/data-listitems.html
如果你真的想要这样的配对项目,要点就是有一个模板,然后像这样:
{{# listItems.three}}
<div class="group">
<article>...</article>
<article>...</article>
</div>
{{/ listItems.three}}
您的 listitems.json
将对应为:
{
"1": {
"articles" : [
{...},
{...}
]
},
"2": {
"articles" : [
{...},
{...}
]
},
"3": {
"articles" : [
{...},
{...}
]
}
}
listitems.three
没有 link 输出文章的数量,只是潜在的数据量。使用这种方法,物品的顺序实际上也是随机的。