因此,我尝试别名另一个视图。但是我收到一个错误,提示我正在调用的json无法呈现。
employee_view
alias AuthAppWeb.EdtrView
def render("employee_dtr.json", %{employee: employee}) do
%{
id: employee.id,
personal_info: employee.personal_info,
edtr: render_one(employee.edtr, __MODULE__, "edtr.json", as: EdtrView)
}end
edtr_view
def render("edtr.json", %{edtr: edtr}) do
%{
id: edtr.id,
m_in: edtr.m_in,
m_out: edtr.m_out,
a_in: edtr.a_in,
a_out: edtr.a_out,
o_in: edtr.o_in,
o_out: edtr.o_out,
status: edtr.status,
sub_status: edtr.sub_status,
dtr_date: edtr.dtr_date
}end
答案 0 :(得分:1)
第二个参数应该是您要调用的视图。您当前正在调用__MODULE__
,它将扩展到被调用的模块。就您而言,EmployeeView
。您将需要以下内容。
render_one(employee.edtr, EdtrView, "edtr.json")