Arrays 希望创建一个4x10表,使用foreach循环以速度列出我的数组
我想循环遍历第一行中的数组清单[1-4],第二行中的数组清单[5-8],然后继续循环,直到输出整个数组Arrays 希望创建一个4x10表,使用foreach循环以速度列出我的数组,arrays,apache,foreach,velocity,Arrays,Apache,Foreach,Velocity,我想循环遍历第一行中的数组清单[1-4],第二行中的数组清单[5-8],然后继续循环,直到输出整个数组 #set ($cats = [ "Accounting", "Admin & Clerical", "Automotive", "Banking", "Broadcast - Journalism", "Business Development", "Construction", "Customer Service", "Design", "Distribution -
#set ($cats = [
"Accounting", "Admin & Clerical", "Automotive", "Banking",
"Broadcast - Journalism", "Business Development", "Construction", "Customer Service",
"Design", "Distribution - Shipping", "Education - Teaching", "Facilities",
"Finance", "General Business", "General Labor", "Government",
"Grocery", "Health Care", "Hotel - Hospitality", "Human Resources",
"Installation - Maint - Repair", "Inventory", "Legal Admin", "Management",
"Manufacturing", "Marketing", "Nurse", "Pharmaceutical",
"Purchasing - Procurement", "QA - Quality Control", "Real Estate", "Research",
"Restaurant - Food Service", "Retail", "Sales", "Skilled Labor - Trades",
"Strategy - Planning", "Supply Chain", "Transportation", "Warehouse"
] )
如何获取数组中的前4项,将它们放在一行中,然后移动到下4项
<table cellpadding="5px" cellspacing="0" width="100%" style="width:100%!important;font-size:9px;font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;font-weight:normal;text-align:center;background:;color:black">
#set ($counter = 0)
#set ($j = )
#foreach ($i in $cats)
#if ( $counter % 2 == 0)
<tr>
<td>$i</td>
<td></td>
<td></td>
<td></td>
</tr>
#else
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
#end
#end
</table>
#设置($counter=0)
#集合($j=)
#foreach($猫中的i)
#如果($counter%2==0)
$i
#否则
#结束
#结束
我一点也不知道速度,但根据我对其他编码语言的了解,试试这样的方法,让我知道它是如何运行的
<table cellpadding="5px" cellspacing="0" width="100%" style="width:100%!important;font-size:9px;font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;font-weight:normal;text-align:center;color:black">
<!-- The two sets in your code here looked superfluous --!>
#foreach ($i in $cats)
#if ( ( $foreach.index - 1 ) % 4 == 0)
<tr>
#end
<td>$i</td>
#if ( ( $foreach.index - 1 ) % 4 == 3 || $foreach.last)
</tr>
#end
#end
</table>
那很好。祝你好运。你有问题吗?我的问题是如何抓住数组的前4个并将它们放在一行中,然后移动到下4个