art.template 循环里面分组。

 

后台提供给我们一个数组,我们要用模版实现上面的格式输出怎么版呢?

下面就是解决方案:

 

 

<h2>循环4个一组</h2>
<script type="text/html" id="temp1">
    <b>
{{each rows as item i}}
    {{if i%4==0}}<b>【{{/if}}
    {{item.userName}}
    {{if i>0 && (i-3)%4==0}}】</b>{{/if}}
{{/each}}

    </ul>
</script>

<script>
    var data={
        "rows":[
            {"userName":"项目1"},
            {"userName":"项目2"},
            {"userName":"项目3"},
            {"userName":"项目4"},
            {"userName":"项目5"},
            {"userName":"项目6"},
            {"userName":"项目7"},
            {"userName":"项目8"},
            {"userName":"项目9"},
            {"userName":"项目10"},
            {"userName":"项目11"},
            {"userName":"项目12"},
            {"userName":"项目13"},
            {"userName":"项目14"},
            {"userName":"项目15"},
            {"userName":"项目16"},
            {"userName":"项目17"},
            {"userName":"项目18"},
            {"userName":"项目19"},
            {"userName":"项目20"}
        ]
    }
    var html=template("temp1",data)

    document.write(html)

</script>

 

 

 

如果这篇文章对您有帮助,您可以打赏我

 

技术交流QQ群:15129679

 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值