理由 我正试图将以下的RoR观点守则转化为普惠制观点:
<代码>List<Object>bjectcontains the data I 我想在3栏中显示
<%
modulo_objects = @objects.length % 3
base = @objects.length / 3
base = base.ceil
case modulo_objects
when 0
cols = [base, base, base]
when 1
cols = [base, base + 1, base]
when 2
cols = [base + 1, base, base + 1]
end
counter = 0
%>
<% 3.times do |i| %>
<td width="220" align="center" style="padding-right: 15px;">
<% cols[i].times do %>
<h1><a href="/objects/show/<%= @objects[counter].urlname %>" ><%= @objects[counter].name %></a></h1>
<% counter = counter + 1 %>
<% end %>
</td>
<% end %>
这是我迄今为止所看到的:
#{extends main.html /}
%{
modulo_objects = objects.size() % 3
base = objects.size() / 3
base = Math.ceil(base)
if(modulo_objects == 0)
cols = [base, base, base]
else if(modulo_objects == 1)
cols = [base, base + 1, base]
else if(modulo_objects == 2)
cols = [base + 1, base, base + 1]
endif
counter = 0
}%
#{list items:1..3, as: i }
<td width="220" align="center" style="padding-right: 15px;">
#{list items:cols[i]}
<a href="@{Objects.show(objects.get(counter).name.replaceAll(" ", "-"))}" >${objects.get(counter).name}</a>
%{ counter = counter + 1 }%
#{/list}
</td>
#{/list}
The idea is to keep the items organised in 3 columns like 1|0|1 4|5|4 or 5|4|5 for example,
I don t really understand if #{list items:cols[i]}
will reproduce ruby s cols[i].times do
.
迄今为止, Java的观点没有两个以上内容。