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