How to look out for particular value in the For loop of the Phoenix HTML.
Like I only want to fetch out the 2nd candidate_pipeline from the @candidate_pipelines. How to do that? Your response will be highly appreciable. Note- Inside my for loop, the variable are depended on candidate_pipeline.
<%= for candidate_pipeline <- @candidate_pipelines do %>
<%= form_for get_candidate_update_changeset(candidate_pipeline), "#", [class: "d-inline", phx_change: "update_candidate_stage"], fn f -> %>
<input type="hidden" value="<%= candidate_pipeline.id %>" name="candidate_id"/>
<%= select f, :job_stage_id, Enum.map(@job_stages, &{&1.name, &1.id}), [class: "custom-select custom-select-sm"] %>
<% end %>
<% end %>
I have used the Enum.at but the problem is that I canāt then use the attribute of the candidate_pipe. For example, then I canāt use the candidate_pipeline.id. Could you solve the above part either by anyway? Note- I have the index value.
Or there is something like this- <%= candidate_pipeline = @candidate_pipelines[index] %>. So that values which will be stores into the variable and further I can access attribute values like candidate_pipeline.id.
I want to fetch out the particular element present at a index value from @candidate_pipelines to a variable. With the help of this variable I can access value like variable.attribute. Mainly, I want to access all parameter that are available at the particular index value of the @candidate_pipelines.
When You use for, each element of @candidate_pipelines is going to be treated. You donāt need to lookup with an index, because it should be the current element.
Thatās what I have done- iterating over the enumerable but I want only 1 at a time that is present at a index, donāt want to iterate over list/enumerable.
Yes, You are right but the problem is that I donāt want other values. It is wastage of time, resource and unwanted value are getting as output. For example- I want only 2nd element but it is iterating over the whole due to which extra data from other index are geeting as output which I donāt want.
For example you can pick the second element in a list this way:
iex(1)> second = fn [_, value| _] -> value end
#Function<6.128620087/1 in :erl_eval.expr/5>
iex(2)> list = [1,2,3]
[1, 2, 3]
iex(3)> second.(list)
2
iex(4)>
Example of defining view functions (page_view.ex) being used in index.html.eex