【发布时间】:2021-12-07 09:09:43
【问题描述】:
我有一个嵌套的地图列表,我想获取地图的特定元素。我该怎么做?
这是我的地图:
[
%Eagle.Content.TemplateFields.TemplateField{
__meta__: #Ecto.Schema.Metadata<:loaded, "template_fields">,
id: 13,
inserted_at: ~N[2021-10-20 12:02:42],
name: "Meta title",
name_slug: "meta_title",
position: nil,
settings: %{"options" => [], "validate" => %{"required" => []}},
template: #Ecto.Association.NotLoaded<association :template is not loaded>,
template_id: 4,
type: "text",
updated_at: ~N[2021-10-20 12:02:42]
},
%Eagle.Content.TemplateFields.TemplateField{
__meta__: #Ecto.Schema.Metadata<:loaded, "template_fields">,
id: 14,
inserted_at: ~N[2021-10-20 12:02:42],
name: "Meta description",
name_slug: "meta_description",
position: nil,
settings: %{"options" => [], "validate" => []},
template: #Ecto.Association.NotLoaded<association :template is not loaded>,
template_id: 4,
type: "text",
updated_at: ~N[2021-10-20 12:02:42]
}
]
我想从第二张地图中获取名字。
现在我有这样的事情:
x = landing_page.template.fields[%{name: "Meta description"}]
我会很感激你的帮助
【问题讨论】:
标签: elixir pattern-matching ecto