小编fly*_*gge的帖子

doT.js每隔3次迭代做一些事情

我有一个看起来像这样的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应该每三次渲染一次.我该怎么做呢?

javascript json dot.js

5
推荐指数
1
解决办法
2734
查看次数

JavaScript:通过交替使用每种类型的对象来排序数组

我有一个像这样的对象数组(按类型排序,相同类型的对象是相同的):

[
    { "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)

javascript arrays sorting

5
推荐指数
1
解决办法
83
查看次数

标签 统计

javascript ×2

arrays ×1

dot.js ×1

json ×1

sorting ×1