(@_@;)我是程序猿,我编程,我快乐,知识改变命运,技术成就梦想   oh yeah!合作VX "w6668263" 联系Email:ye583025823@126.com

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

 
 

posted on 2018-12-21 16:54  一个草率的龙果果  阅读(806)  评论(0编辑  收藏  举报

导航