gpt4 book ai didi

phoenix-framework - Phoenix 模板列表中的错误

转载 作者:行者123 更新时间:2023-12-05 00:15:17 27 4
gpt4 key购买 nike

我正在尝试从模板中的列表( <%= @evento %> )中提取值,但出现此错误:

lists in Phoenix.HTML and templates may only contain integers representing bytes, binaries or other lists, got invalid entry: %Skeleton.News.Evento{__meta__: #Ecto.Schema.Metadata<:loaded, "news_eventos">, date: "DEZ 2011", id: 69, imgPaths: ["images/fabasa/eventos/one/1.jpg", "images/fabasa/eventos/one/2.jpg", "images/fabasa/eventos/one/3.jpg", "images/fabasa/eventos/one/10.jpg"], inserted_at: ~N[2017-06-30 12:38:15.452214],...  

所以,我的问题是如何在我仍然可以在我的模板中迭代的数据类型结构中转换它?

最佳答案

您不能在模板中打印这样的列表,因为模板只允许打印 iolists,它们是包含整数、二进制文件(在 Elixir 中也称为 String)或 iolists 的列表。

如果要打印 inspect列表的表示(您在 iex 中看到的那个),您可以执行以下操作:

<%= inspect @evento %>

要遍历列表,您可以使用 for :
<%= for event <- @evento %>
<%= event.id %>
<% end %>

关于phoenix-framework - Phoenix 模板列表中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44854265/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com