如何处理 Elixir/Phoenix 模板中的空案例?
How can I handle the empty case in Elixir/Phoenix templates?
在模板中,我在行程中有几天的迭代:
<%= for day <- @days do %>
<tr>
<td><%= day.number %></td>
<td><%= day.main_event_time %></td>
<td><%= day.main_event %></td>
<td><%= day.location %></td>
<td><%= day.who %></td>
<td><%= day.summary %></td>
<td><%= day.lodging %></td>
<td><%= link "Show", to: day_path(@conn, :show, day) %></td>
<td><%= link "Edit", to: day_path(@conn, :edit, day) %></td>
<td><%= link "Delete", to: day_path(@conn, :delete, day), method: :delete %></td>
</tr>
<% end %>
我希望在没有日期的情况下出现不同的消息。我该怎么做?
你可以把它放在你的 for
理解之前或之后:
<%= if Enum.empty?(@days) do %>
No days yet.
<% end %>
在模板中,我在行程中有几天的迭代:
<%= for day <- @days do %>
<tr>
<td><%= day.number %></td>
<td><%= day.main_event_time %></td>
<td><%= day.main_event %></td>
<td><%= day.location %></td>
<td><%= day.who %></td>
<td><%= day.summary %></td>
<td><%= day.lodging %></td>
<td><%= link "Show", to: day_path(@conn, :show, day) %></td>
<td><%= link "Edit", to: day_path(@conn, :edit, day) %></td>
<td><%= link "Delete", to: day_path(@conn, :delete, day), method: :delete %></td>
</tr>
<% end %>
我希望在没有日期的情况下出现不同的消息。我该怎么做?
你可以把它放在你的 for
理解之前或之后:
<%= if Enum.empty?(@days) do %>
No days yet.
<% end %>