[英]LiveView: How to process data in a rendered comprehension list
在Phoenix中,如果需要對模板中的數據進行處理,可以將數據傳遞給視圖進行處理,輸出回模板。 例如:
## index.html.heex
<%= for a <- @articles do %>
<%= a.title %>
<%= get_category(a.category_id).name %>
## article_view
def get_category(id) do
Categories.get_article_category!(id)
但是,這與 LiveView 不同。 我試圖在理解中調用一個組件來處理數據:
## index.html.heex
<%= for a <- @articles do %>
<%= a.title %>
<%= live_component @socket, CategoryComponent, id: a.category_id %>id %>
但是現在,我不知道如何制作類別組件(handle_info?)來放置每篇文章的類別名稱。
在 LiveView 中更新渲染列表中的數據的正確方法是什么?
我不能在這上面花太多時間,所以我只是使用上下文中的方法並將 LiveView 查詢放在那里
# index.html.heex
<%= App.Categories.get_category!(a.category_id).name %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.