我有一个看起来像这样的doT.js模板:
{{?it.books.length }}
{{~it.books :value}}
<li>
<article class='Teaser'>
<a href='{{=value.url}}' title='{{=value.title}}'>
<img src='{{=value.image}}' />
</a>
<h3>
<a href='{{=value.url}}' title='{{=value.title}}'>{{=value.title}}</a>
</h3>
</article>
</li>
// this should only be rendered every 3rd time
<br class='clear' />
{{~}}
{{?}}
Run Code Online (Sandbox Code Playgroud)
最后的br-Tag应该每三次渲染一次.我该怎么做呢?
我有一个像这样的对象数组(按类型排序,相同类型的对象是相同的):
[
{ "type":"A", "height":50, "width":80 },
{ "type":"A", "height":50, "width":80 },
{ "type":"B", "height":20, "width":100 },
{ "type":"B", "height":20, "width":100 },
{ "type":"C", "height":90, "width":10 }
]
Run Code Online (Sandbox Code Playgroud)
我希望将所有这些对象放在一个数组中,该数组通过交替使用每种类型的对象来排序:
[
{ "type":"A", "height":50, "width":80 },
{ "type":"B", "height":20, "width":100 },
{ "type":"C", "height":90, "width":10 },
{ "type":"A", "height":50, "width":80 },
{ "type":"B", "height":20, "width":100 }
]
Run Code Online (Sandbox Code Playgroud)