Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 如何枚举一个外星成员灵丹妙药凤凰的索引_Elixir_Ecto_Phoenix - Fatal编程技术网

Elixir 如何枚举一个外星成员灵丹妙药凤凰的索引

Elixir 如何枚举一个外星成员灵丹妙药凤凰的索引,elixir,ecto,phoenix,Elixir,Ecto,Phoenix,我正在寻找如何在html show中获得我的EXTO成员的自定义索引-从资源mix phx.gen.html生成。目标是每个新的post都应该有编号。我曾尝试在PostsController中创建该函数,但我无法解决它 <%= for post <- @posts do %> <%= post.title %> <% end %> 大家好,欢迎来到堆栈溢出:) 我很确定您正在寻找: <%= @posts |> Enum.with_ind

我正在寻找如何在html show中获得我的EXTO成员的自定义索引-从资源
mix phx.gen.html
生成。目标是每个新的
post
都应该有编号。我曾尝试在PostsController中创建该函数,但我无法解决它

<%= for post <- @posts do %>

<%= post.title %>

<% end %>

大家好,欢迎来到堆栈溢出:)

我很确定您正在寻找:

<%= @posts |> Enum.with_index() |> Enum.map(fn({post, index}) ->  %>

  <%= index %>

  <%= post.title %>

<% end %>
Enum.with_index()|>Enum.map(fn({post,index})->%>
这样一来,
应该指向每一个EXTO成员并对其进行排序

致以最诚挚的问候,ykostov的变体用于:

<%= for {post, index} <- @posts |> Enum.with_index() do %>
<%= index %>
<%= post.title %>
<% end %>


作为良好实践,建议始终在函数调用中包含(),即使它没有参数。是的,这很重要,但在这种情况下没有错,不是吗?:)(答案编辑)是的,使用
for
对我来说更简单,+1